业务对象是 Foo.cs
如果 Foo 的属性运行自定义逻辑怎么办?那么创建可以更改 Foo 对象内部数据并返回我不期望的值的 Foo 对象不是一个坏主意吗?!
public class FooBuilder
{
private string bar = "defaultBar";
private string baz = "defaultBaz";
private string bling = "defaultBling";
public FooBuilder Bar(string value)
{
bar = value;
return this;
}
public FooBuilder Baz(string value)
{
baz = value;
return this;
}
public FooBuilder Bling(string value)
{
bling = value;
return this;
}
public Foo Build()
{
return new Foo {Bar = bar, Baz = baz, Bling = bling};
}
}