-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDecorator.cs
72 lines (53 loc) · 1.42 KB
/
Decorator.cs
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Singleton
{
internal class Decorator
{
}
//Idea: Think of a plain ice cream.You can add toppings like chocolate syrup, sprinkles,
//or nuts. Each topping decorates the ice cream in a different way.
//The Decorator pattern allows us to add new behavior to objects without changing their structure.
public interface IIcecream
{
string CreateIceCream();
}
public class PlainIceCream:IIcecream
{
public PlainIceCream()
{
}
public string CreateIceCream()
{
return "Plain IceCream Created";
}
}
public class IceCreamChocolate : IIcecream
{
private IIcecream _Icecream { get; }
public IceCreamChocolate( IIcecream icecream)
{
_Icecream = icecream;
}
public string CreateIceCream()
{
return _Icecream.CreateIceCream() + "with Chocolate";
}
}
public class IceCreamVanilla : IIcecream
{
private IIcecream _Icecream { get; }
public IceCreamVanilla(IIcecream icecream)
{
_Icecream = icecream;
}
public string CreateIceCream()
{
return _Icecream.CreateIceCream() + "with VanillA";
}
}
}