|
|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?FreeOZ用户注册
x
R++ , 来自Bell实验室的C++扩展, 如上图所示R++在C++ OOP的基础上增加了一个Rules维度,使得可以在C++的class中定义规则和基于规则的动作。如果你对Java很熟悉的话,应该听说过一个Drool的软件包,其用XML的方式时间了Java的商业规则引擎,而R++就是采用了C++的方式实现了Drool所做的事情。
附件为R++用户手册和R++的一个简单例子, 同样的例子如果用Drool来表达的话应该像下面这个样子:
- <rule name="update area">
- <parameter identifier="rectangle">
- <class>Rectangle>
- parameter>
-
- <java:condition>
- rectangle.height > 0 && rectangle.width > 0
- java:condition>
- <java:consequence>
- stockOffer.area = rectangle.height * rectangle.width;
- java:consequence>
- rule>
复制代码
R++写出来的是这样:
Rectangle.rh
- class Rectangle {
- private:
- monitored int height, width;
- int area;
- public:
- Rectangle(int h, int w) : height(h), width(w) {}
- add_to_height(int delta) { set_height(height + delta); }
- rule update_area;
- friend ostream& operator<<(ostream&, Rectangle * const);
- };
复制代码
Rectangle.rC
- #include <iostream.h>
- $include "Rectangle.rh"
- rule Rectangle::update_area {
- height > 0 &&
- width > 0
- =>
- area = height * width;
- }
- ostream& operator<< (ostream& s, Rectangle * const p) {
- return s << "Rectangle " << p->height << " * "
- << p->width << " = "
- << p->area;
- }
复制代码 |
评分
-
查看全部评分
|