Esempio n. 1
0
        public void Ex1()
        {
            // Buildern skickas till "directorn"
            var director = new Director();
            var builder  = new ConcreteBuilder();

            director.Builder = builder;

            // Initiera konstruktionsprocessen
            Console.WriteLine("Standard basic product:");
            director.BuildMinimalViableProduct();

            // Slutresultatet kommer från byggobjektet
            Console.WriteLine(builder.GetProduct().ListParts());

            // Skapa något mer avancerat

            Console.WriteLine("Standard full featured product:");
            director.BuildFullFeaturedProduct();

            // Samma kod som innan för att generera resultat
            Console.WriteLine(builder.GetProduct().ListParts());

            // Det går att använda "builder pattern" utan "director"
            Console.WriteLine("Custom product:");
            builder.BuildPartA();
            builder.BuildPartC();
            Console.Write(builder.GetProduct().ListParts());
        }
Esempio n. 2
0
        /***
         * 抽象的建造者只关心对象有哪些步骤,
         * 具体的建造者只关心如何实现每一个具体的步骤,
         * 指挥者只关心构建的顺序,
         * 三方各司其职,很好的隔离了构建对象的步骤和顺序,
         * 一但指挥者和建造者确定了,开发者只需要关心如何实现和更新具体步骤就行了,
         */
        public static void Test()
        {
            Builder  builder1 = new ConcreteBuilder();
            Director director = new Director(builder1);

            director.Consttruct();
            var product = builder1.GetResult();

            product.Show();
        }
Esempio n. 3
0
        private void btnMontar_Click(object sender, EventArgs e)
        {
            this.Size = new Size(448, 450);

            var    director = new Director();
            var    builder  = new ConcreteBuilder();
            string aux      = "";

            builder.BuildPartA();
            builder.BuildPartB();
            builder.BuildPartC();

            var     decide    = new EscreveStr();
            Product resultado = new Product();

            string str = decide.Texto(ckbA.Checked, ckbB.Checked, ckbC.Checked);

            picCarro.Image = imageList1.Images[resultado.EscolheImagem(str)];
        }
Esempio n. 4
0
        public string Texto(bool a, bool b, bool c)
        {
            Product  produto = new Product();
            Director diretor = new Director();
            var      builder = new ConcreteBuilder();

            diretor.Builder = builder;
            string str = "";

            if (a)
            {
                str += "A";
            }
            if (b)
            {
                str += "B";
            }
            if (c)
            {
                str += "C";
            }
            return(str);
        }