|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.Threading.Tasks; |
| 6 | + |
| 7 | +namespace CreationalPatterns.AbstractFactory |
| 8 | +{ |
| 9 | + public enum PizzaType |
| 10 | + { |
| 11 | + Cheese, |
| 12 | + Veggie |
| 13 | + }; |
| 14 | + |
| 15 | + public abstract class Pizza |
| 16 | + { |
| 17 | + public string Name { get; set; } |
| 18 | + public Dough Dough { get; set; } |
| 19 | + |
| 20 | + public abstract void Prepare(); |
| 21 | + |
| 22 | + public void Bake() |
| 23 | + { |
| 24 | + Console.WriteLine("Bake for 15 minutes"); |
| 25 | + } |
| 26 | + |
| 27 | + public void cut() |
| 28 | + { |
| 29 | + Console.WriteLine("Cutting the pizza into 8 slices"); |
| 30 | + } |
| 31 | + |
| 32 | + public void box() |
| 33 | + { |
| 34 | + Console.WriteLine("Pack the pizza in a box"); |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + // American Pizzas |
| 39 | + public class CheesePizza : Pizza{ |
| 40 | + private string description = "Cheese Pizza"; |
| 41 | + private PizzaIngredientFactory ingredientFactory; |
| 42 | + |
| 43 | + public CheesePizza(PizzaIngredientFactory ingredientFactory) |
| 44 | + { |
| 45 | + this.ingredientFactory = ingredientFactory; |
| 46 | + this.Name = ingredientFactory.GetName() + " Style " + description; |
| 47 | + } |
| 48 | + |
| 49 | + public override void Prepare() |
| 50 | + { |
| 51 | + Console.WriteLine("Preparing {0}", this.Name); |
| 52 | + this.Dough = ingredientFactory.CreateDough(); |
| 53 | + Console.WriteLine("Creating {0}", this.Dough.GetName()); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + public class VeggiePizza : Pizza |
| 58 | + { |
| 59 | + private string description = "Veggie Pizza"; |
| 60 | + private PizzaIngredientFactory ingredientFactory; |
| 61 | + |
| 62 | + public VeggiePizza(PizzaIngredientFactory ingredientFactory) |
| 63 | + { |
| 64 | + this.ingredientFactory = ingredientFactory; |
| 65 | + this.Name = ingredientFactory.GetName() + " Style " + description; |
| 66 | + } |
| 67 | + |
| 68 | + public override void Prepare() |
| 69 | + { |
| 70 | + Console.WriteLine("Preparing {0}", this.Name); |
| 71 | + this.Dough = ingredientFactory.CreateDough(); |
| 72 | + Console.WriteLine("Creating {0}", this.Dough.GetName()); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | +} |
0 commit comments