public void TestMethodBuilder_Example() { string p = "Leo "; var ptb = new PersonThinBuilder(p); var pd = new PersonDirector(ptb); pd.CreatePersion(); Console.WriteLine(pd.GetResult()); }
static void Main(string[] args) { PersonDirector personDirector = new PersonDirector(); var person = personDirector.ConstructPerson(new ManBuilder()); Console.WriteLine(person.Head); Console.WriteLine(person.Body); Console.WriteLine(person.Foot); Console.WriteLine("Hello World!"); }
/// <summary> /// 建造者模式 /// </summary> static void TestBuilder() { PersonThinBuilder ptb = new PersonThinBuilder("draw", "pen"); PersonDirector personDirector = new PersonDirector(ptb); personDirector.CreatePerson(); PersonThinBuilder pfb = new PersonThinBuilder("draw", "pen"); PersonDirector pdFat = new PersonDirector(pfb); pdFat.CreatePerson(); }
static void Main(string[] args) { IBuild fatBuild = new PersonThinBuilder(09) as IBuild; PersonDirector personDirector = new PersonDirector(); personDirector.SetBuilder(fatBuild); personDirector.BuildPeople(); Console.WriteLine("_________________________________________"); personDirector.SetBuilder(new PersonFatBuilder(90)); personDirector.BuildPeople(); }
/// <summary> /// 建造者 模式 的用户界面 /// </summary> void Builder_main() { Sprite s = new Sprite(); Graphics NewGra = new Graphics(); Sprite NewSpri = new Sprite(); //首先根据用户的需要定义一个 需要建造的小人 PersonThinBuilder ThinPerson = new PersonThinBuilder(NewGra, NewSpri); //通知 建造模式的 指挥者 建造房子 PersonDirector Perdic = new PersonDirector(ThinPerson); //指挥类 进行建造 Perdic.CreatPerson(); }