-
Notifications
You must be signed in to change notification settings - Fork 0
/
Decorator.cs
52 lines (43 loc) · 930 Bytes
/
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
using System;
public class Program
{
public interface IComponent
{
string Operation();
}
public class Component : IComponent
{
public Component()
{
}
public string Operation()
{
return "this is a basic component";
}
}
public class Decorator : IComponent
{
private IComponent comp;
public string AddedState = " and added state";
public Decorator(IComponent c)
{
comp = c;
}
public string Operation()
{
return comp.Operation() + " with decorator";
}
public string AddedBehaviour()
{
return " and added behaviour";
}
}
public static void Main()
{
Console.WriteLine("Hello World");
IComponent comp = new Component();
Console.WriteLine(comp.Operation());
Decorator comp2 = new Decorator(comp);
Console.WriteLine(comp2.Operation() + comp2.AddedBehaviour() + comp2.AddedState);
}
}