Created
October 30, 2016 02:32
-
-
Save anonymous/67e4fe5fe0477d34b24125f741ad0b3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace DesignPatterns | |
{ | |
public abstract class Beverage | |
{ | |
public string description = "Unknown beverage"; | |
public virtual string GetDescription() | |
{ | |
return description; | |
} | |
public abstract double Cost(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace DesignPatterns | |
{ | |
public abstract class CondimentDecorator : Beverage | |
{ | |
public abstract new string GetDescription(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace DesignPatterns | |
{ | |
public class Espresso : Beverage | |
{ | |
public Espresso() | |
{ | |
description = "Espresso"; | |
} | |
public override double Cost() | |
{ | |
return 1.99; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace DesignPatterns | |
{ | |
public class Mocha : CondimentDecorator | |
{ | |
Beverage beverage; | |
public Mocha(Beverage beverage) | |
{ | |
this.beverage = beverage; | |
} | |
public override string GetDescription() | |
{ | |
return beverage.GetDescription() + " Mocha"; | |
} | |
public override double Cost() | |
{ | |
return 0.20 + beverage.Cost(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace DesignPatterns | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Beverage espresso = new Espresso(); | |
Console.WriteLine($"{espresso.description}"); | |
Console.WriteLine(espresso.GetType()); | |
Console.WriteLine($"{espresso.GetDescription()} and {espresso.Cost()}"); | |
espresso = new Mocha(espresso); | |
Console.WriteLine($"{espresso.description}"); | |
Console.WriteLine(espresso.GetType()); | |
Console.WriteLine($"{espresso.GetDescription()} and {espresso.Cost()}"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment