0
有一個容器類,它有一個整數集合。我的目標是計算所有整數的總和。我在這裏使用工作流規則引擎。這兩條規則有點像如下:爲什麼規則在對象的上下文中執行多次?
RuleName: Initializer
Priority: 2
Condition : 1==1
ThenActions:
this.i = 0;
ReEvaluationBehavior: Always
----
RuleName: Looping
Priority: 1
Condition: this.i < this.Items.Count
ThenActions:
this.total = this.total + this.Items[this.i];
this.i = this.i + 1;
ReEvaluationBehavior: Always
這只是一個抽象表示。容器類定義爲:
public class NumberContainer
{
public int i;
public int ItemCount
{
get
{
return this.Items.Length;
}
private double total;
public double Total
{
get { return total; }
set { total = value; }
}
private double[] items;
public double[] Items
{
get { return items; }
set { items = value; }
}
//Other stuff...
}
}
我只在這裏顯示了重要的字段。所有這些(即填充的容器對象和規則集)都被提供給規則引擎執行。
爲什麼Looping
規則會執行多次,而Initializer
規則只會執行一次?這是否與Chaining有關?是否我們在Looping
規則中設置了i
的值,並且相同的變量恰好是相應規則條件的一部分?