分享

表驱动法 规则引擎

 Jimmy Booker 2011-03-14

表驱动法 规则引擎

2007-08-25

分类:

版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://nxk4124./logs/45698480.html

发觉主程的代码为何我读起来那么不耐烦的原因了,他的代码里有大量的IF-ELSE-THEN。

读起来很费劲儿,解决的方案有1、 引入表驱动法简化代码结构。2、规则引擎。

==============================

1、表驱动法,将CASE语句转为数据表。

直接参照《代码大全》P412页即可~  

简单地说就是建立一个HASH表,代替复杂的逻辑判断。应用起来很有难度,不过在各种费率以及保险费率查询中应用广泛。

charType = charTypeTable[ inputChar ];

 

  • 直接访问表:例子为闰年、保险费率(用年龄作为下标,直接查找处费率即可!!聪明啊!!)
灵活的消息,这个例子尚未吃透,明天继续。
 
此方法的优点为,根本就不需要引入一个规则引擎这么复杂的东西。仅仅是教会程序员这么思考问题即可!!
 
============================== 

 

2、 已知的规则引擎有(FOR .NET):

Open Source Rule Engines are free, open-source rule engines in C#.

Drools.NET
Drools.NET is a Business Rules Engine (BRE) based on Charles Forgy's Rete algorithm. Developers can now exploit a powerful Rule Engine through a completely managed .NET code base! Drools.NET is based on Jboss Rules(http://www./products/rules), and comes with all the features of that Rules Engine.
NxBRE
NxBRE .NET Business Rule Engine is the first open-source rule engine for the .NET platform and a lightweight Business Rules Engine aka Rule-Based Engine.
Simple Rule Engine
Simple Rule Engine (SRE) is a lightweight forward chaining inference rule engine for .NET. Its 'simple' because of the simplicity in writing and understanding the rules written in XML, but this 'simple' engine can solve complex problems.
FlexRule BRMS Solution
FlexRule is a full managed BRMS and BRE written in C# that provides a procedure execution engine and RETE based inference engine for FREE of charge as an express version. It has ability to be used in API mode and/or high level language mode(Xml based and S-Expression). All the features can be fully extensible by developers.

More features and flexibilities for professionals and enterprise systems are available too.

================== 

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多