Posts

Showing posts from April, 2009

Decorator Pattern C#

using System; namespace DecoratorPattern { class Program { static void Main(string[] args) { Beverage bvrgObj = new WhiteChocolate(); Mocha mocha = new Mocha(bvrgObj); WhippedCream whippedCream = new WhippedCream(mocha); String str = whippedCream.getDescription(); } } public abstract class Beverage { public abstract String getDescription(); } public class WhiteChocolate : Beverage { public WhiteChocolate() { } public override string getDescription() { return "White Chocolate"; } } public abstract class Condiment : Beverage { } public class Mocha : Condiment { Beverage beverage; public Mocha(Beverage bvrg) { beverage = bvrg; } public override string getDescription() { return beverage.getDescription() + ", Mocha"