-
Notifications
You must be signed in to change notification settings - Fork 0
/
Decorator.cs
74 lines (59 loc) · 1.5 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
73
74
using System;
namespace Decorator
{
public interface IComputer
{
string GetInfo();
double GetPrice();
}
public class Computer: IComputer
{
public string name { get; private set; }
public Computer(string name)
{
this.name = name;
}
public string GetInfo()
{
return name;
}
public double GetPrice()
{
return 500;
}
}
public abstract class ComputerDecorator: IComputer
{
protected IComputer computer;
public ComputerDecorator(IComputer computer)
{
this.computer = computer;
}
public abstract string GetInfo();
public abstract double GetPrice();
}
public class OperativeMemoryDecorator: ComputerDecorator
{
public OperativeMemoryDecorator(IComputer computer) : base(computer) { }
public override string GetInfo()
{
return computer.GetInfo() + " 8 gb";
}
public override double GetPrice()
{
return computer.GetPrice() + 100;
}
}
public class VideocardDecorator : ComputerDecorator
{
public VideocardDecorator(IComputer computer) : base(computer) { }
public override string GetInfo()
{
return computer.GetInfo() + " Videocard GTX";
}
public override double GetPrice()
{
return computer.GetPrice() + 250;
}
}
}