The shopping cart rule engine DSL
As the final example in the book, I am showing off a DSL for processing a shopping cart. Here is how it looks like:
behavior of preferred_customer upon bad_credit: authorize_funds cart.Total * 0.5, "For preferred customers we only authorize half the amount" upon cart_update: when cart.Total > 1000: add_cart_discount 5, "Preferred members gets 5% discount for orders over 1,000$"
And this:
behavior of default_customer
upon bad_credit:
authorize_funds cart.Total, "We require full authorization of the amount in low credit rating scenarios"
Where we defined preferred customer and default customer as:
define preferred_customer: customer.TotalPurchaseAmount > 5000 define default_customer: customer.TotalPurchaseAmount <= 5000
The implementation is surprisingly easy, and I was able to walk through the reasoning for this implementation rather than the usual when [condition] in a way that I hope would make sense.
You can look at the implementation here: https://rhino-tools.svn.sourceforge.net/svnroot/rhino-tools/BDSLiB/trunk
Comments
I understand chapter13 is the missing chapter in your e-book,you have a link to sourcecode for chapter 13 i bought your book with some source code just till chapter 7 i feel pretty annoyed by this why is there no source code to create and process your examples?
I hope you are able to give a link
Paul,
the source code is available here:
rhino-tools.svn.sourceforge.net/.../BDSLiB
Hello Ayende,
Thanks for your response I noticed the link but i can't extract the code, when i use the example code i have no database with tables that do correspond to the shopping card example? is there an example db, i have to install?
No, there is not DB in the sample
hello mr. ayende,
I am working on the samples do i have to use a subversion extractor to download these sample trunk ?
I on there site to find out
thanks for your attention
Use a SVN client like tortoise svn or the command line client.
Hello mr Ayende,
I got the example's running.
Many Chapters explaine"10,12,13" the rules to direct and process orders.
within the setup there didn't process any "order" for example ,is there such example that follows the rules?
This would be explaining a lot and make some test possible.
its an impressive work of art
I don't understand the question, can you expand on that?
Hello mr Ayende,
running the shopping card 'ch13' it created rules engine but it isn't processing an order physically, there is no order send true the stages. It would explaine a lot if an order did process the stages that where created in the examples.
I haven't figure out how to handle the h potter order.
I created a better example here:
rhino-tools.svn.sourceforge.net/.../Program.cs
Comment preview