public static void Main() { // Create director and builders Director director = new Director(); Builder b1 = new ConcreteBuilder1(); Builder b2 = new ConcreteBuilder2(); // Construct two products director.Construct(b1); Product p1 = b1.GetResult(); p1.Show(); director.Construct(b2); Product p2 = b2.GetResult(); p2.Show(); // Wait for user Console.ReadKey(); }
private static void ShowBuilder() { Console.WriteLine("================================================"); Console.WriteLine("Pattern code (Builder):"); Director director = new Director(); Builder b1 = new ConcreteBuilder1(); Builder b2 = new ConcreteBuilder2(); director.Construct(b1); Product p1 = b1.GetResult(); p1.Show(); director.Construct(b2); Product p2 = b2.GetResult(); p2.Show(); Console.WriteLine("Real code (Builder):"); Shop shop = new Shop(); VehicleBuilder builder = new ScooterBuilder(); shop.Construct(builder); builder.Vehicle.Show(); builder = new CarBuilder(); shop.Construct(builder); builder.Vehicle.Show(); builder = new MotorCycleBuilder(); shop.Construct(builder); builder.Vehicle.Show(); }
public void TestBuilder() { var director = new Director(); var partsAb = new List <string> { "PartA", "PartB" }; var partsXy = new List <string> { "PartX", "PartY" }; Builder b1 = new ConcreteBuilder1(); Builder b2 = new ConcreteBuilder2(); director.Construct(b1); var p1 = b1.GetResult(); var list = p1.Show(true); foreach (var pt in partsAb) { Assert.Contains(pt, list); } director.Construct(b2); var p2 = b2.GetResult(); var list2 = p2.Show(true); foreach (var pt in partsXy) { Assert.Contains(pt, list2); } }
public static void BuilderStructural() { // Create director and builders var director = new Director(); Log.WriteLine("{0} has Created", director.GetType().Name); Builder b1 = new ConcreteBuilder1(); Builder b2 = new ConcreteBuilder2(); Log.WriteLine("{0} has Created", b1.GetType().Name); Log.WriteLine("{0} has Created", b2.GetType().Name); Log.AddSeparator(5); // Construct two products director.Construct(b1); Log.WriteLine("{0} has Construct {1}", director.GetType().Name, b1.GetType().Name); Product p1 = b1.GetResult(); Log.WriteLine("Get Resuult"); p1.Show(); Log.AddSeparator(5); director.Construct(b2); Log.WriteLine("{0} has Construct {1}", director.GetType().Name, b2.GetType().Name); Product p2 = b2.GetResult(); Log.WriteLine("Get Resuult"); p2.Show(); // Wait for user }
private static void BuilderModeTest() { Builder builder = new ConcreteBuilder1(); Product product = Director.Construct(builder); product.Show(); Console.ReadKey(); }
static void Main() { Director director = new Director(); Builder b1 = new ConcreteBuilder1(); Builder b2 = new ConcreteBuilder2(); director.Construct(b1); Product p1 = b1.GetResult(); p1.Show(); director.Construct(b2); Product p2 = b2.GetResult(); p2.Show(); }
public Client() { Director director = new Director(); Builder b1 = new ConcreteBuilder1(); Builder b2 = new ConcreteBuilder2(); director.Construct(b1); Product p1 = b1.GetResult(); p1.Show(); director.Construct(b2); Product p2 = b2.GetResult(); p2.Show(); }
public void Check_Builder_Pattern() { Director director = new Director(); Builder b1 = new ConcreteBuilder1(); director.Construct(b1); CP_Builder.Product p1 = b1.GetResult(); p1.Show(); Builder b2 = new ConcreteBuilder2(); director.Construct(b2); CP_Builder.Product p2 = b2.GetResult(); p2.Show(); }
static void Main(string[] args) { Director director = new Director(); Rainnier.DesignPattern.Builder.Structural.Builder b1 = new ConcreteBuilder1(); Rainnier.DesignPattern.Builder.Structural.Builder b2 = new ConcreteBuilder2(); // Construct two products Product p1 = director.Construct(b1); p1.Show(); Product p2 = director.Construct(b2); p2.Show(); }
public static void BuilderPattern() { Director director = new Director(); Builder b1 = new ConcreteBuilder1(); Builder b2 = new ConcreteBuilder2(); director.Construct(b1); Product p1 = b1.GetResult(); p1.Show(); director.Construct(b2); Product p2 = b2.GetResult(); p2.Show(); Console.Read(); }
public static void Main() { // Create director and builders Director director = new Director(); Builder b1 = new ConcreteBuilder1(); Builder b2 = new ConcreteBuilder2(); // Construct two products director.Construct(b1); Product p1 = b1.GetResult(); p1.Show(); director.Construct(b2); Product p2 = b2.GetResult(); p2.Show(); // Wait for user Console.Read(); }
private static void Main(string[] args) { var director = new Director(); Builder b1 = new ConcreteBuilder1(); Builder b2 = new ConcreteBuilder2(); director.Construct(b1); var p1 = b1.GetResult(); p1.Show(); director.Construct(b2); var p2 = b2.GetResult(); p2.Show(); Console.ReadKey(); }
static bool TestBuilderPattern() { Console.WriteLine("TESTING THE BUILDER DESIGN PATTERN: "); Director director = new Director(); IBuilder b1 = new ConcreteBuilder1(); IBuilder b2 = new ConcreteBuilder2(); director.Construct(b1); Console.WriteLine(b1.GetProduct()); director.Construct(b2); Console.WriteLine(b2.GetProduct()); return(true); }
public void ConstructTest() { Director director = new Director(); IBuilder b1 = new ConcreteBuilder1(); IBuilder b2 = new ConcreteBuilder2(); director.Construct(b1); Product p1 = b1.GetResult(); Assert.AreEqual("部件A部件B", p1.Show()); director.Construct(b2); Product p2 = b2.GetResult(); p2.Show(); Assert.AreEqual("部件X部件Y", p2.Show()); }
public void TestBuilderTheory() { var director = new Director(); var builder1 = new ConcreteBuilder1(); var builder2 = new ConcreteBuilder2(); director.Construct(builder1); var product1 = builder1.GetResult(); product1.Show(); director.Construct(builder2); var product2 = builder2.GetResult(); product2.Show(); }
static void Main(string[] args) { AbstractFactoryClient client = new AbstractFactoryClient(MANUFACTURES.PRODUCT1FACTORY); client.ProductList(); client = new AbstractFactoryClient(MANUFACTURES.PRODUCT2FACTORY); client.ProductList(); IBuilder builder1 = new ConcreteBuilder1(); Console.WriteLine($"New Product created: {Manufacture.Construct(builder1)}"); builder1 = new ConcreteBuilder2(); Console.WriteLine($"New Product created: {Manufacture.Construct(builder1)}"); Creator creator = new Creator(); IProduct product; product = creator.GetProduct(PRODUCT.TYPE1); Console.WriteLine(product.Description); product = creator.GetProduct(PRODUCT.TYPE2); Console.WriteLine(product.Description); LazyObject.Get("first"); LazyObject.Get("second"); LazyObject.ShowAll(); LazyObject.Get("third"); LazyObject.Get("first"); LazyObject.ShowAll(); Person personClient = new Client() { FirstName = "Ivan", SecondName = "Ivanov", OrdersCount = 5 }; Person personEmployee = new Employee() { FirstName = "Petr", SecondName = "Petrov", Salary = 1000 }; ToStringVisitor visitor = new ToStringVisitor(); Console.WriteLine(visitor.DynamicVisit(personClient)); Console.WriteLine(visitor.DynamicVisit(personEmployee)); Console.WriteLine("Complete"); Console.ReadKey(); }
public void CreateProductWithBuilder1() { // Create concrete builder No 1 Builder builder = new ConcreteBuilder1(); // Create concrete builder No 2 //BuilderTest.Builder builder = new BuilderTest.ConcreteBuilder2(); // Configure Director with builder Director director = new Director(builder); // Construct Product from Director director.Construct(); // Get result Product product = builder.GetResult(); Assert.AreEqual(product.ToString(), "Hello World"); }
private void Start() { // Create director and builders Director director = new Director(); Builder b1 = new ConcreteBuilder1(); Builder b2 = new ConcreteBuilder2(); // Construct two products director.Construct(b1); Product p1 = b1.GetResult(); p1.Show(); director.Construct(b2); Product p2 = b2.GetResult(); p2.Show(); }
public static void Main(string[] args) { Director director = new Director(); IBuilder b1 = new ConcreteBuilder1(); IBuilder b2 = new ConcreteBuilder2(); director.Construct(b1); Product p1 = b1.GetResult(); p1.Show(); director.Construct(b2); Product p2 = b2.GetResult(); p2.Show(); Console.Read(); }
static void Main(string[] args) { Director director = new Director(); IBuilder builder1 = new ConcreteBuilder1(); IBuilder builder2 = new ConcreteBuilder2(); director.Construct(builder1); Product product1 = builder1.GetResult(); product1.Show(); director.Construct(builder2); Product product2 = builder2.GetResult(); product2.Show(); Console.Read(); }
public static void Main() { // tworzymy instancje director Director director = new Director(); //tworzymy instancje b1 i b2 dla buildera 1 i 2 Builder b1 = new ConcreteBuilder1(); Builder b2 = new ConcreteBuilder2(); // wytwarzamy dwa produkty //z instancji buildera b1 wytwarzamy produkt p1 i metoda show wyswietalmy arrayliste director.Construct(b1); Product p1 = b1.GetResult(); p1.Show(); //z instancji buildera b2 wytwarzamy produkt p2 i metoda show wyswietalmy arrayliste director.Construct(b2); Product p2 = b2.GetResult(); p2.Show(); Console.WriteLine(DateTime.Now.ToString("h:mm:ss tt")); long a = DateTime.Now.Ticks; for (int i = 0; i < 10000000; i++) { Builder b3 = new ConcreteBuilder1(); director.Construct(b3); Product p3 = b3.GetResult(); p3.Show2(); } Console.WriteLine(DateTime.Now.ToString("h:mm:ss tt")); long b = DateTime.Now.Ticks; Console.WriteLine((b - a) / TimeSpan.TicksPerMillisecond); // nacisnij guzik Console.Read(); }
static void Main(string[] args) { //Create the director Director director = new Director(); // Create two builder Builder builderA = new ConcreteBuilder1(); Builder builderB = new ConcreteBuilder2(); //Build the product director.Construct(builderA); Product productA = builderA.GetResult(); productA.Show(); director.Construct(builderB); Product productB = builderB.GetResult(); productB.Show(); Console.Read(); }
static void Main(string[] args) { Console.WriteLine("Structural example:"); Director director = new Director(); Builder b1 = new ConcreteBuilder1(); Builder b2 = new ConcreteBuilder2(); director.Construct(b1); Product p1 = b1.GetResult(); p1.Show(); director.Construct(b2); Product p2 = b2.GetResult(); p2.Show(); Console.WriteLine(); Console.WriteLine("Real-world example:"); VehicleBuilder builder; Shop shop = new Shop(); builder = new ScooterBuilder(); shop.Construct(builder); builder.Vehicle.Show(); builder = new CarBuilder(); shop.Construct(builder); builder.Vehicle.Show(); builder = new MotorCycleBuilder(); shop.Construct(builder); builder.Vehicle.Show(); Console.ReadKey(); }
static void BuilderTester() { #region sample 1 var director = new Topics.Design_Patterns.Creational.Builder.Director(); Builder b1 = new ConcreteBuilder1(); Builder b2 = new ConcreteBuilder2(); // Construct two products director.Construct(b1); var p1 = b1.GetResult(); p1.Show(); director.Construct(b2); var p2 = b2.GetResult(); p2.Show(); #endregion #region sample 2 // Create shop with vehicle builders var shop = new Shop(); // Construct and display vehicles VehicleBuilder builder = new ScooterBuilder(); shop.Construct(builder); builder.Vehicle.Show(); builder = new CarBuilder(); shop.Construct(builder); builder.Vehicle.Show(); builder = new MotorCycleBuilder(); shop.Construct(builder); builder.Vehicle.Show(); #endregion }
/// <summary> /// 建造者模式 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button5_Click(object sender, EventArgs e) { // 客户找到电脑城老板说要买电脑,这里要装两台电脑 // 创建指挥者和构造者 Director director = new Director(); Builder b1 = new ConcreteBuilder1(); Builder b2 = new ConcreteBuilder2(); // 老板叫员工去组装第一台电脑 director.Construct(b1); // 组装完,组装人员搬来组装好的电脑 Computer computer1 = b1.GetComputer(); computer1.Show(); // 老板叫员工去组装第二台电脑 director.Construct(b2); Computer computer2 = b2.GetComputer(); computer2.Show(); Console.Read(); }