Dekorator

0

Witam,
Czy ktoś może mi wskazać błąd, co robię tutaj nie tak, że wyświetla mi tylko 1 składnik zamiast kilku na output? Wzorzec dekorator.

using System;
using System.Collections.Generic;
using System.Text;

namespace Decorator
{
    public abstract class DecorationPizza : Pizza
    {
        protected Pizza tempPizza;
        public DecorationPizza(Pizza newPizza)
        {
            tempPizza = newPizza;
        }

        public string getDescription()
        {
            return tempPizza.getDescription();
        }
        public decimal getPrice()
        {
            return tempPizza.getPrice();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Text;

namespace Decorator
{
    public interface Pizza
    {
        public String getDescription();
        public decimal getPrice();
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace Decorator
{
    public class PlainPizza : Pizza
    {
        public string getDescription()
        {
            return "Dough";
        }

        public decimal getPrice()
        {
            return 10;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Text;

namespace Decorator
{
    public class TomatoSouce : DecorationPizza
    {
        public TomatoSouce(Pizza newPizza) : base(newPizza)
        {
            Console.WriteLine("Adding Souce");
        }

        public string getDescription()
        {
            return tempPizza.getDescription() + ", Tomato Souce";
        }

        public decimal getPrice()
        {
            return tempPizza.getPrice() + 3;
        }
    }
}
using System;

namespace Decorator
{
    class Program
    {
        static void Main(string[] args)
        {
            Pizza order = new TomatoSouce(new Mozarella(new PlainPizza()));
            Console.WriteLine("Ingrendients: " + order.getDescription());
            Console.WriteLine("Price: " + order.getPrice());
        }
    }
}
using System;
using System.Collections.Generic;
using System.Text;

namespace Decorator
{
    public class Mozarella : DecorationPizza
    {
        public Mozarella(Pizza newPizza): base(newPizza)
        {
            Console.WriteLine("Adding Mozarella");
        }
        public string getDescription()
        {
            return tempPizza.getDescription() + ", mozarella";
        }
        public decimal getPrice()
        {
            return tempPizza.getPrice() + 3;
        }
    }
}
1

A weź sobie ustaw brakepointa na początku i prześledź jak leci i coś się może nauczysz. Bez seansu brać się za wzorce jak nie umie sie debugowac

1 użytkowników online, w tym zalogowanych: 0, gości: 1