static void Main(string[] args) { // client code ElectornicsManufacture em = new ElectornicsManufacture(); // builds phones CellPhoneBuilder builder = new CellPhoneBuilder(); em.set_builder(builder); em.build_iphone(); CellPhone iPhone = (CellPhone)em.get_product(); iPhone.use_phone(); em.build_samsung_note(); CellPhone note = (CellPhone)em.get_product(); note.use_phone(); // builds laptops LaptopBuilder builder2 = new LaptopBuilder(); em.set_builder(builder2); em.build_thinkpad(); Laptop tp = (Laptop)em.get_product(); tp.use_laptop(); }
private CellPhone(CellPhoneBuilder builder) { _cpu = builder.Cpu; _memory = builder.Memory; _memoryCapacity = builder.MemoryCapacity; _screenType = builder.ScreenType; _microSdSlot = builder.MicroSdSlot; }
private static void BuilderPatternExample() { CellPhoneBuilder builder = new CellPhoneBuilder { Cpu = "i7", Memory = 16, MemoryCapacity = 64, MicroSdSlot = null, ScreenType = "FHD" }; CellPhone cellPhone = builder.Build(); Console.WriteLine(cellPhone); }