Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Decorator Design Pattern
//Title of this code //Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { Pizza pizza = new LargePizza(); Console.WriteLine(pizza.GetDescription()); Console.WriteLine(pizza.CalculateCost()); pizza = new Chees(pizza); Console.WriteLine(pizza.GetDescription()); Console.WriteLine(pizza.CalculateCost()); pizza = new Ham(pizza); Console.WriteLine(pizza.GetDescription()); Console.WriteLine(pizza.CalculateCost()); } public abstract class Pizza { public string Description{get; set;} public abstract string GetDescription(); public abstract double CalculateCost(); } public class LargePizza : Pizza { public LargePizza() { Description = "Large Pizza"; } public override string GetDescription() { return Description; } public override double CalculateCost() { return 10.00; } } public class PizzaDecorator : Pizza { protected Pizza _pizza; public PizzaDecorator(Pizza pizza) { _pizza = pizza; } public override string GetDescription() { return _pizza.Description; } public override double CalculateCost() { return _pizza.CalculateCost(); } } public class Chees : PizzaDecorator { public Chees(Pizza pizza): base (pizza) { Description = "Chees"; } public override string GetDescription() { return _pizza.GetDescription() + ", " + Description; } public override double CalculateCost() { return _pizza.CalculateCost()+2.00; } } public class Ham : PizzaDecorator { public Ham(Pizza pizza): base (pizza) { Description = "Ham"; } public override string GetDescription() { return _pizza.GetDescription() + ", " + Description; } public override double CalculateCost() { return _pizza.CalculateCost()+2.00; } } } }
run
|
edit
|
history
|
help
0
2 point gradient (v2)
LCM Q 3
Strings Mix Complete
Program to implement RamaKrishna
Math 5.83b
Palindrome 2
HelloWorld
Generic 2 parameters hierarchy
adxaxsdc
Singleton Design Pattern