Advertisement
kadyr

Untitled

Oct 24th, 2022
907
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1.  
  2. public abstract class Pizza
  3. {
  4.     public void prepare()
  5.     {
  6.         Console.WriteLine("Preparing " + this.GetType().Name);
  7.     }
  8.  
  9.     public void bake()
  10.     {
  11.            
  12.     }
  13.  
  14.     public void cut()
  15.     {
  16.        
  17.     }
  18.  
  19.     public void box()
  20.     {
  21.        
  22.     }
  23. }
  24. public class PizzaStore
  25. {
  26.     public Pizza orderPizza(string type)
  27.     {
  28.         Pizza pizza = createPizza(type);
  29.         pizza.prepare();
  30.         pizza.bake();
  31.         pizza.cut();
  32.         pizza.box();
  33.         return pizza;
  34.     }
  35.  
  36.     public Pizza createPizza(string type)
  37.     {
  38.         Pizza pizza = null;
  39.         if (type == "cheese")
  40.         {
  41.             pizza = new CheesePizza();
  42.         }
  43.         else if (type == "pepperoni")
  44.         {
  45.             pizza = new PepperoniPizza();
  46.         }
  47.         else if (type == "clam")
  48.         {
  49.             pizza = new ClamPizza();
  50.         }
  51.         else if (type == "veggie")
  52.         {
  53.             pizza = new VeggiePizza();
  54.         }
  55.         return pizza;
  56.     }
  57. }
  58.  
  59. public class VeggiePizza : Pizza
  60. {
  61. }
  62.  
  63. public class ClamPizza : Pizza
  64. {
  65. }
  66.  
  67. public class PepperoniPizza : Pizza
  68. {
  69. }
  70.  
  71. public class CheesePizza : Pizza
  72. {
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement