與傳統屬性相比,使用它的最大好處是什麼?爲什麼使用Fluent界面?
我知道實例名稱的重複消失了,但是這些都是?
public class PropClass
{
public Object1 object1 { get; set; }
public Object2 object2 { get; set; }
}
PropClass propClass = new PropClass();
propClass.object1 = o1;
propClass.object2 = o2;
public class FluentClass
{
public Object1 object1 { get; private set; }
public Object2 object2 { get; private set; }
public FluentClass SetObject1(Object1 o1)
{
object1 = o1;
return this;
}
public FluentClass SetObject2(Object1 o2)
{
object1 = o2;
return this;
}
}
FluentClass fluentClass = new FluentClass().SetObject1(o1).SetObject1(o2);
'Fluent Interfaces'在處理'Specification Pattern'時很有用。它將n個規範鏈接爲[如何動態組合條件]中給出的規範(http://stackoverflow.com/questions/21406492/how-to-combine-conditions-dynamically) – Lijo 2014-01-29 09:56:25