Example #1
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            //一家披萨店自由点餐
            APizza a = new APizza();

            a.Make();

            BPizza b = new BPizza();

            b.Make();

            CPizza c = new CPizza();

            c.Make();

            DPizza d = new DPizza();

            d.Make();

            //简单工厂模式
            SimplePizzaFactory simple = new SimplePizzaFactory();

            simple.CreateIstance(PizzaType.A).Make();
            simple.CreateIstance(PizzaType.B).Make();
            simple.CreateIstance(PizzaType.C).Make();
            simple.CreateIstance(PizzaType.D).Make();

            //工厂模式
            APizzaFactory apizzaF = new APizzaFactory();

            apizzaF.Create().Make();

            BPizzaFactory bpizzaF = new BPizzaFactory();

            bpizzaF.Create().Make();

            CPizzaFactory cpizzaF = new CPizzaFactory();

            cpizzaF.Create().Make();

            DPizzaFactory dpizzaF = new DPizzaFactory();

            dpizzaF.Create().Make();

            //抽象工厂
            AbstractFactory1 apf1 = new AbstractFactory1();//分厂1

            apf1.CreateA().Make();
            apf1.CreateB().Make();
            apf1.CreateC().Make();
            apf1.CreateD().Make();

            AbstractFactory2 apf2 = new AbstractFactory2();//分厂2

            apf2.CreateA().Make();
            apf2.CreateB().Make();
            apf2.CreateC().Make();
            apf2.CreateD().Make();
        }
        public Pizza OrderPizza(string type)
        {
            Pizza pizza = SimplePizzaFactory.CreatePizza(type);

            pizza.Prepare();
            pizza.Bake();
            pizza.Cut();
            pizza.Box();
            return(pizza);
        }
Example #3
0
        static void Main(string[] args)
        {
            SimplePizzaFactory pizzaFactory = new SimplePizzaFactory();
            PizzaStore         pizzaStore   = new PizzaStore(pizzaFactory);

            Pizza pizza = pizzaStore.OrderPizza("cheese");

            Console.WriteLine("A customer ordered a {0}", pizza.GetName());
            Console.WriteLine("");

            Console.ReadLine();
        }
Example #4
0
        static void Main(string[] args)
        {
            SimplePizzaFactory factory = new SimplePizzaFactory();
            PizzaStore         store   = new PizzaStore(factory);

            Pizza pizza = store.orderPizza("cheese");

            Console.WriteLine("We ordered a " + pizza.getName() + "\n");
            Console.WriteLine(pizza);

            pizza = store.orderPizza("veggie");
            Console.WriteLine("We ordered a " + pizza.getName() + "\n");
            Console.WriteLine(pizza);

            pizza = store.orderPizza("pepperoni");
            Console.WriteLine("We ordered a " + pizza.getName() + "\n");
            Console.WriteLine(pizza);

            Console.ReadKey();
        }
Example #5
0
 public PizzaStore(SimplePizzaFactory factory)
 {
     this.factory = factory;
 }