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";
}
}

public class WhippedCream : Condiment
{
Beverage beverage;
public WhippedCream(Beverage bvrg)
{
beverage = bvrg;
}

public override string getDescription()
{
return beverage.getDescription() + ", WhippedCream";
}
}
}

Comments

Popular posts from this blog

WPF How to Dispose ViewModel when the associated UserControl (Not Window) closes?

C# How to unit test Dispatcher

WPF: How to Deep Copy WPF object (e.g. UIElement) ?