public static void DecoratorCommand() { Pizza mypizza = new ThickCrust(); mypizza = new Pepperoni(mypizza); mypizza = new Sausage(mypizza); Console.WriteLine("This is the decorator pattern. It allows behaviors to be added to an existing object dynamically during runtime."); Console.WriteLine("Here we use a decorator pattern to make a pizza, and add things to it, and then to tell us it's cost."); Console.WriteLine($"Pizza costs: {mypizza.cost()}"); Console.ReadLine(); }
static void Main(string[] args) { ThickCrust thickCrust = new ThickCrust(); PizzaPriceInfo(thickCrust); OnionPizzaDecorator onionPizza = new OnionPizzaDecorator(thickCrust); CheesePizzaDecorator cheesePizza = new CheesePizzaDecorator(onionPizza); PizzaPriceInfo(cheesePizza); }
public ICrust BuildCrust() { var crust = new ThickCrust(typeof(ThickCrust).Name); return(crust); }