DSL Boo完整实例

DSL

image

Model

clip_image004

对应的DSL内容

treatment of default_customer
upon bad_credit:
authorize_funds cart.Total,  "We require full authorization of the amount in low credit rating scenarios"

define preferred_customer:
customer.TotalPurchaseAmount > 5000
define default_customer:
customer.TotalPurchaseAmount <= 5000

treatment 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$"

DSL集成

// create the actual policies
var policies = new CustomerPolicies("Scripts");
// get a policy for this customer
AbstractCustomerPolicy policy = policies.For(preferredCustomer);
Console.WriteLine("Selected policy for {0}: {1} ",
                  policy.CustomerSpecification,
                  policy);
// somehow here we derive what our current state is...
// check if customer have treatment for the bad credit state
if (policy.HasTreatmentFor(States.BadCredit) == false)
return;
// get the treatment to apply
Treatment treatment = policy.TreatmentForState(States.BadCredit);
Console.WriteLine("Treatment for bad credit is: {0}", treatment.Description);
// execute the treatment on the shopping cart view
treatment.Execute(shoppingCart.GenerateView());

 

 

关于这个例子的详细内容可以参考 http://www.cnblogs.com/2018/category/399342.html 阅读相关的图书

转载于:https://www.cnblogs.com/2018/archive/2012/10/27/2623627.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值