-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
68 lines (55 loc) · 2.25 KB
/
Program.cs
File metadata and controls
68 lines (55 loc) · 2.25 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
using System;
using Weervoorspelling.Patterns.Memento;
using Weervoorspelling.Patterns.Observer;
using Weervoorspelling.Patterns.Strategy;
using Weervoorspelling.Patterns.Prototype;
using Weervoorspelling.Patterns.Decorator;
namespace Weervoorspelling
{
class Program
{
static void Main(string[] args)
{
var weatherForecast = new WeerVoorspelling
{
Description = "Sunny",
TemperatureDay = 20,
TemperatureNight = 10,
Humidity = 50
};
// Memento
var beheerder = new Beheerder();
beheerder.Save(weatherForecast.SaveMemento());
// Observer
var weerOnderwerp = new WeerOnderwerp();
var userObserver = new UserObserver();
weerOnderwerp.Attach(userObserver);
weerOnderwerp.SetTemperature(weatherForecast.TemperatureDay);
// Strategy
IForecastStrategy strategy = new GedetailleerdeForecastStrategy();
strategy.DisplayForecast(weatherForecast);
// Prototype
var prototype = new PrototypeWeervoorspelling
{
Description = "Cloudy",
TemperatureDay = 15,
TemperatureNight = 8,
Humidity = 70
};
var clonedForecast = (PrototypeWeervoorspelling)prototype.Clone();
clonedForecast.Description = "Rainy";
Console.WriteLine("\nCloned Forecast:");
Console.WriteLine($"Description: {clonedForecast.Description}");
// Decorator
IForecastStrategy simpleStrategy = new SimpleForecastStrategy();
IForecastStrategy decoratedStrategy = new CelsiusDecorator(simpleStrategy);
decoratedStrategy.DisplayForecast(weatherForecast);
decoratedStrategy = new FahrenheitDecorator(simpleStrategy);
decoratedStrategy.DisplayForecast(weatherForecast);
// Undo (Memento)
weatherForecast.RestoreMemento(beheerder.Undo());
Console.WriteLine("\nRestored Forecast:");
strategy.DisplayForecast(weatherForecast);
}
}
}