版權聲明:轉(zhuǎn)載時請以超鏈接形式標明文章原始出處和作者信息及本聲明
http://nxk4124./logs/45698480.html
發(fā)覺主程的代碼為何我讀起來那么不耐煩的原因了,他的代碼里有大量的IF-ELSE-THEN。
讀起來很費勁兒,解決的方案有1、 引入表驅(qū)動法簡化代碼結構。2、規(guī)則引擎。
==============================
1、表驅(qū)動法,將CASE語句轉(zhuǎn)為數(shù)據(jù)表。
直接參照《代碼大全》P412頁即可~
簡單地說就是建立一個HASH表,代替復雜的邏輯判斷。應用起來很有難度,不過在各種費率以及保險費率查詢中應用廣泛。
charType = charTypeTable[ inputChar ];
- 直接訪問表:例子為閏年、保險費率(用年齡作為下標,直接查找處費率即可?。÷斆靼。。。?/li>
靈活的消息,這個例子尚未吃透,明天繼續(xù)。
此方法的優(yōu)點為,根本就不需要引入一個規(guī)則引擎這么復雜的東西。僅僅是教會程序員這么思考問題即可??!
==============================
2、 已知的規(guī)則引擎有(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.
==================