示例#1
0
        static void Main(string[] args)
        {
            CakeBase cakeBase = new CakeBase();

            PrintProductDetails(cakeBase);

            CreamDecorator creamCake = new CreamDecorator(cakeBase);

            PrintProductDetails(creamCake);

            CherryDecorator cherryCake = new CherryDecorator(creamCake);

            PrintProductDetails(cherryCake);

            ArtificialScentDecorator scentedCake = new ArtificialScentDecorator(cherryCake);

            PrintProductDetails(scentedCake);

            NameCardDecorator nameCardCake = new NameCardDecorator(scentedCake);

            PrintProductDetails(nameCardCake);

            PastryBase pastryBase = new PastryBase();

            PrintProductDetails(pastryBase);

            CreamDecorator  creamPastry  = new CreamDecorator(pastryBase);
            CherryDecorator cherryPastry = new CherryDecorator(creamPastry);

            PrintProductDetails(cherryPastry);

            Console.ReadKey();
        }
示例#2
0
 public CakeMaker()
 {
     currentCake = null;
     ingredients = new List <CakeBase>();
     ingredients.Add(new ChocolateCake("Chocolate Cake"));
     ingredients.Add(new FruitCake("Fruit Cake"));
     ingredients.Add(new ChocoCream("Choco Cream", null));
     ingredients.Add(new WhippedCream("Whipped Cream", null));
     ingredients.Add(new Strawberry("Strawberry", null));
     ingredients.Add(new ForestFruits("Forest Fruits", null));
 }
示例#3
0
        public void SetCakeType(string Name)
        {
            CakeBase cb = getCakeBaseByName(Name);

            if (currentCake == null)
            {
                if (!(cb is ToppingBase))
                {
                    currentCake = cb.Copy();
                }
            }
        }
示例#4
0
        public void AddToppingBase(string Name)
        {
            Console.WriteLine(Name);
            CakeBase cb = getCakeBaseByName(Name);

            if (cb != null)
            {
                if (currentCake != null)
                {
                    if (cb is ToppingBase)
                    {
                        CakeBase cbCopy = cb.Copy();
                        ((ToppingBase)cbCopy).NextBase = currentCake.Copy();
                        currentCake = cbCopy;
                    }
                }
            }
        }
示例#5
0
        public static void Execute()
        {
            // Let us create a Simple Cake Base first
            CakeBase cBase = new CakeBase();

            PrintProductDetails(cBase);

            // Lets add cream to the cake
            CreamDecorator creamCake = new CreamDecorator(cBase);

            PrintProductDetails(creamCake);

            // Let now add a Cherry on it
            CherryDecorator cherryCake = new CherryDecorator(creamCake);

            PrintProductDetails(cherryCake);

            // Lets now add Scent to it
            ArtificialScentDecorator scentedCake = new ArtificialScentDecorator(cherryCake);

            PrintProductDetails(scentedCake);

            // Finally add a Name card on the cake
            NameCardDecorator nameCardOnCake = new NameCardDecorator(scentedCake);

            PrintProductDetails(nameCardOnCake);

            // Lets now create a simple Pastry
            PastryBase pastry = new PastryBase();

            PrintProductDetails(pastry);

            // Lets just add cream and cherry only on the pastry
            CreamDecorator  creamPastry  = new CreamDecorator(pastry);
            CherryDecorator cherryPastry = new CherryDecorator(creamPastry);

            PrintProductDetails(cherryPastry);
        }
示例#6
0
 public Fruit(string name, CakeBase Next)
     : base(name, Next)
 {
 }
 public Strawberry(string name, CakeBase Next)
     : base(name, Next)
 {
 }
示例#8
0
 public void RemoveCake()
 {
     currentCake = null;
 }
示例#9
0
 public Cream(string name, CakeBase Next)
     : base(name, Next)
 {
 }
示例#10
0
 public ForestFruits(string name, CakeBase Next)
     : base(name, Next)
 {
 }
 public WhippedCream(string name, CakeBase Next)
     : base(name, Next)
 {
 }
示例#12
0
 public ToppingBase(string name, CakeBase Next)
     : base(name)
 {
     NextBase = Next;
 }