-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
72 lines (61 loc) · 1.78 KB
/
Program.cs
File metadata and controls
72 lines (61 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
namespace MyLittleCoffeeShop
{
internal class Program
{
static void Main(string[] args)
{
ICoffee basicCoffee = new BasicCoffee();
Console.WriteLine(basicCoffee.GetDescription());
Console.WriteLine(basicCoffee.GetCost());
ICoffee galao = new GalaoDecorator(basicCoffee);
Console.WriteLine(galao.GetDescription());
Console.WriteLine(galao.GetCost());
}
public interface ICoffee
{
string GetDescription();
double GetCost();
}
public class BasicCoffee : ICoffee
{
public string GetDescription()
{
return "Basic Coffee";
}
public double GetCost()
{
return 5.0;
}
}
public abstract class CoffeDecorator : ICoffee
{
protected ICoffee _coffee;
public CoffeDecorator(ICoffee coffee)
{
_coffee = coffee;
}
public virtual double GetCost()
{
return _coffee.GetCost();
}
public virtual string GetDescription()
{
return _coffee.GetDescription();
}
}
public class GalaoDecorator : CoffeDecorator
{
public GalaoDecorator(ICoffee coffee) : base(coffee)
{
}
public override string GetDescription()
{
return base.GetDescription() + ", with Milk";
}
public override double GetCost()
{
return base.GetCost() + 2.0;
}
}
}
}