示例#1
0
        public static void Main()
        {
            ComputerShop shop = new ComputerShop();

            ComputerBuilder builder;

            builder = new LaptopBuilder();
            shop.ConstructComputer(builder);
            builder.Computer.DisplayConfiguration();

            builder = new DesktopBuilder();
            shop.ConstructComputer(builder);
            builder.Computer.DisplayConfiguration();

            builder = new AppleBuilder();
            shop.ConstructComputer(builder);
            builder.Computer.DisplayConfiguration();
        }
示例#2
0
        private void btnDesktop_Click(object sender, EventArgs e)
        {
            NameValueCollection inputs = createCollection();

            // Step 1 Concrete builder
            ISystemBuilder systemBuilder = new DesktopBuilder();

            // Step 2 Director
            ConfigurationBuilder director = new ConfigurationBuilder();

            director.BuildSystem(systemBuilder, inputs);

            // Step 3 return the system
            ComputerSystem system = systemBuilder.GetSystem();

            txtResult.Text =
                string.Format($"RAM: {system.RAM}, HDDSize: {system.HDDSize}, " +
                              $"Keyboard: {system.Keyboard}, Mouse: {system.Mouse}");
        }