这些年我工作中开发的一个体会就是要重视引擎的开发。那什么叫引擎呢?我的理解就是它本质上就不是代码驱动的,就好比我们如果要实现一个客户购物,我们一般会这么写
class Customer {
public void buy(Product product,int count)
{
Shop shop=product.getShop();
int productCount =shop.getCount(product);
if(productCount>=count)
{
this.pay(product,count);
shop.sell(product,count);
}
}
}
那如果是用引擎来写了,那就是完全不同的了
RuleEngine{
public void runRule(Rule rule)
{
Condiction cond=rule.getCondiction();
if(cond.check())
{
Operation[] operas=rule.getOperations();
runOperation(operas);
}
}
}
这样的话,我们就把用户购物完全的抽象出来了,当然rule,和ruleengine的实现会是比较复杂的, 复杂到可能要几万行代码才能搞定,这也是为什么大家基本上都是面向具体业务开发的原因了。