Ayende @ Rahien

Unnatural acts on source code

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

paul
12/15/2008 10:47 PM by
paul

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
12/16/2008 08:32 AM by
paul

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?

Ayende Rahien
12/16/2008 02:39 PM by
Ayende Rahien

No, there is not DB in the sample

paul
12/16/2008 08:24 PM by
paul

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

Ayende Rahien
12/16/2008 10:17 PM by
Ayende Rahien

Use a SVN client like tortoise svn or the command line client.

paul
12/21/2008 03:25 PM by
paul

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

Ayende Rahien
12/21/2008 08:51 PM by
Ayende Rahien

I don't understand the question, can you expand on that?

paul
12/22/2008 08:00 AM by
paul

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.

Comments have been closed on this topic.