Need guidance on how can I write a series of "rule based" code efficiently?
Hi guys,
I'm looking for resources on how can I write a series of "rule-based" code efficiently.
What I mean by rule-based is kinda like having a UI for user
IF quantity [remains] [3], [alert user] IF quantity [less than] [2], [email admin] etc etc..
Any help would be greatly appreciated!
This is more of a conceptual view of how you COULD do this. The code provided does work but encourage that you try to understand what it does BEFORE using it.
I have written it in JavaScript because that is where my head is at the moment, the idea should carry across irrespective of language.
Frontend
I won't explain how to write the UI as that depends on a million factors so instead will show you what the UI would build up behind the scenes.
Essentially what you want to be building up is an array with the conditions like so…
Then you would send off a request to the backend to add the rules where they would run.
Backend
As far as running the rules, you would built up some validators to test your product against.
Create a function that accepts a product and the rules from the frontend.
This would give you an array of actions you need to take.
@nblackburn Thanks for the detailed code examples! That really helps a lot! No worries, I just needed some code reference to have a rough feel of the concept in building such rule-based system.
I've understood a thing or two from your examples :) Thanks a lot! Really appreciate it!
Please sign in to leave a comment.