Ejemplo n.º 1
0
        public Pizza2 orderPizza(string type)
        {
            Pizza2 pizza = createPizza(type);

            pizza.prepare();
            pizza.bake();
            pizza.cut();
            pizza.box();

            return(pizza);
        }
Ejemplo n.º 2
0
        private void button20_Click(object sender, EventArgs e)
        {
            Form1 f1 = (Form1)Application.OpenForms["Form1"];

            //------------------Simple Factory-----------------
            f1.GB_Status_AppendText_Nextline("------------------Simple Factory(encapsulating object creation by composition)-----------------", Color.Black);
            SimplePizzaFactory spPizzaFactory = new SimplePizzaFactory();
            Simple_PizzaStore  pzstore        = new Simple_PizzaStore(spPizzaFactory);
            Pizza pizza = pzstore.orderPizza("cheese");

            f1.GB_Status_AppendText_Nextline("mr.A ordered a " + pizza.name, Color.Red);

            pizza = pzstore.orderPizza("peperoni");
            f1.GB_Status_AppendText_Nextline("mr.B ordered a " + pizza.name, Color.Red);

            pizza = pzstore.orderPizza("veggie");
            f1.GB_Status_AppendText_Nextline("mr.C ordered a " + pizza.name, Color.Red);

            //------------------Factory Method-----------------
            f1.GB_Status_AppendText_Nextline("------------------Factory Method(encapsulating object creation by inheritance)-----------------", Color.Black);
            PizzaStore korean_pizza_store = new Korean_PizzaStore();

            pizza = korean_pizza_store.orderPizza("cheese");
            f1.GB_Status_AppendText_Nextline("mr.A ordered a " + pizza.name, Color.Red);
            pizza = korean_pizza_store.orderPizza("peperoni");
            f1.GB_Status_AppendText_Nextline("mr.B ordered a " + pizza.name, Color.Red);

            PizzaStore NY_pizza_store = new NY_PizzaStore();

            pizza = NY_pizza_store.orderPizza("cheese");
            f1.GB_Status_AppendText_Nextline("mr.A ordered a " + pizza.name, Color.Red);
            pizza = NY_pizza_store.orderPizza("peperoni");
            f1.GB_Status_AppendText_Nextline("mr.B ordered a " + pizza.name, Color.Red);


            //------------------Abstract Factory-----------------
            Pizza2 pizza2 = null;

            f1.GB_Status_AppendText_Nextline("------------------Abstract Factory(encapsulating object creation by composition)-----------------", Color.Black);
            PizzaStore2 NY_pizza_store2 = new NY_PizzaStore2();

            pizza2 = NY_pizza_store2.orderPizza("cheese");
            f1.GB_Status_AppendText_Nextline("mr.A ordered a " + pizza2.name, Color.Red);
            pizza2 = NY_pizza_store2.orderPizza("peperoni");
            f1.GB_Status_AppendText_Nextline("mr.B ordered a " + pizza2.name, Color.Red);

            PizzaStore2 Korean_pizza_store2 = new Korean_PizzaStore2();

            pizza2 = Korean_pizza_store2.orderPizza("cheese");
            f1.GB_Status_AppendText_Nextline("mr.A ordered a " + pizza2.name, Color.Red);
            pizza2 = Korean_pizza_store2.orderPizza("peperoni");
            f1.GB_Status_AppendText_Nextline("mr.B ordered a " + pizza2.name, Color.Red);
        }
Ejemplo n.º 3
0
        protected override Pizza2 createPizza(string type)
        {
            Pizza2 pizza = null;
            PizzaIngredientFactory ingredientfactory = new Korean_PizzaIngredientFactory();

            if (type.Equals("cheese"))
            {
                pizza      = new CheesePizza2(ingredientfactory);
                pizza.name = "Korean CheesePizza";
            }
            else if (type.Equals("peperoni"))
            {
                pizza      = new PeperoniPizza2(ingredientfactory);
                pizza.name = "Korean peperoni Pizza";
            }
            return(pizza);
        }