コード例 #1
0
        static void Main(string[] args)
        {
            PizzaChef   pizzaChef   = new PizzaChef();
            PastaChef   pastaChef   = new PastaChef();
            SeaFoodChef seaFoodChef = new SeaFoodChef();

            pizzaChef.SetNextHandler(pastaChef).SetNextHandler(seaFoodChef);

            foreach (string request in new string[] { "Pizza", "Pasta", "Sea Food", "Salad" })
            {
                pizzaChef.HandleRequest(request);
            }

            Console.ReadLine();
        }
コード例 #2
0
ファイル: Builder.cs プロジェクト: wang080134/DesignPatterns
        public override void Execute()
        {
            var chef = new PizzaChef();

            chef.SetPizzaRecipe(new PepperoniPizzaRecipe());
            chef.ConstructPizza();
            Pizza pepperoniPizza = chef.ServePizza();

            Assert.Equal(Sauce.Tomato, pepperoniPizza.Sauce);
            Assert.Equal(Topping.Pepperoni | Topping.Cheese, pepperoniPizza.Toppings);

            chef.SetPizzaRecipe(new SpecialPizzaRecipe());
            chef.ConstructPizza();
            Pizza specialPizza = chef.ServePizza();

            Assert.Equal(Sauce.Spicy, specialPizza.Sauce);
            Assert.Equal(Topping.Bacon | Topping.Cheese | Topping.Onion | Topping.Sausage, specialPizza.Toppings);
        }
コード例 #3
0
 public Pizza()
 {
     chef = new PizzaChef();
 }