与传统属性相比,使用它的最大优势是什么?
我知道实例名称的重复已经消失了,但这就是全部吗?
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);