-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDecoratorPattern.cs
51 lines (43 loc) · 1.01 KB
/
DecoratorPattern.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
// DecoratorPattern/Program.cs
using System;
namespace DecoratorPattern
{
// Component
public abstract class Car
{
public abstract void Assemble();
}
// ConcreteComponent
public class BasicCar : Car
{
public override void Assemble() => Console.WriteLine("Basic car assembled.");
}
// Decorator
public class CarDecorator : Car
{
private readonly Car _car;
public CarDecorator(Car car)
{
_car = car;
}
public override void Assemble() => _car.Assemble();
}
// ConcreteDecorator
public class SportsCar : CarDecorator
{
public SportsCar(Car car) : base(car) {}
public override void Assemble()
{
base.Assemble();
Console.WriteLine("Adding features of Sports Car.");
}
}
class Program
{
static void Main()
{
Car sportsCar = new SportsCar(new BasicCar());
sportsCar.Assemble();
}
}
}