Advertisement
kadyr

Untitled

Nov 9th, 2022
709
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. public class PizzaStore
  2. {
  3.     public Pizza orderPizza(string type)
  4.     {
  5.         Pizza creatablePizza = createPizza(type);
  6.         creatablePizza.prepare();
  7.         creatablePizza.bake();
  8.         creatablePizza.cut();
  9.         creatablePizza.box();
  10.         return creatablePizza;
  11.     }
  12.  
  13.     public Pizza createPizza(string type)
  14.     {
  15.         Pizza pizza = null;
  16.         if (type == "cheese")
  17.         {
  18.             pizza = new CheesePizza();
  19.         }
  20.         else if (type == "pepperoni")
  21.         {
  22.             pizza = new PepperoniPizza();
  23.         }
  24.         else if (type == "clam")
  25.         {
  26.             pizza = new ClamPizza();
  27.         }
  28.         else if (type == "veggie")
  29.         {
  30.             pizza = new VeggiePizza();
  31.         }
  32.  
  33.         return pizza;
  34.     }
  35. }
  36.  
  37. public class PizzaDecorator : Pizza
  38. {
  39.     protected Pizza pizza;
  40.  
  41.     public PizzaDecorator(Pizza pizza)
  42.     {
  43.         this.pizza = pizza;
  44.     }
  45.  
  46.     public override void prepare()
  47.     {
  48.         pizza.prepare();
  49.     }
  50. }
  51.  
  52. public class CheeseAroundPizza : PizzaDecorator
  53. {
  54.     public CheeseAroundPizza(Pizza pizza) : base(pizza)
  55.     {
  56.         Name = pizza.Name + "with cheese Around";
  57.         Cost = pizza.Cost + 5;
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement