Design Pattern 1-Builder

xiaoxiao2021-03-06  61

Using system;

namespace Pattern {///

/// Summary description for Class1 /// public interface builder {void buildPartA ();. void buildPartB (); product getProduct ();} public class product {public string PUBLIC STRING DATE; public product () {}} public class director {private builder myb; public director (builder b) {this.myb = b;} public product construct () {

Myb.buildparta (); myb.buildpartb (); return myb.getProduct ();

}

} Public class ConcreateBuilder1: builder {private product p = new product (); public ConcreateBuilder1 () {} public void buildPartA () {p.name = "A"; System.Console.WriteLine ( "build1 part name a"); } Public void buildpartb () {p.date = "b"; system.console.writeline ("build1 part b");} public product getProduct () {system.console.writeline ("build1 product"); return P }}

public class ConcreateBuilder2: builder {private product p = new product (); public ConcreateBuilder2 () {} public void buildPartA () {p.name = "A"; System.Console.WriteLine ( "build2 part name a");} Public void buildpartb () {p.date = "b"; system.console.writeline ("build2 part b");} public product getProduct () {system.console.writeline ("build 2 product"); return P ;}}} // Build mode Builder Director D = New Director (New ConcreateBuilder1 ()); D.Construct ();

D = New Director (New ConcreateBuilder2 ()); D.Construct ();

转载请注明原文地址:https://www.9cbs.com/read-113109.html

New Post(0)