-
Notifications
You must be signed in to change notification settings - Fork 634
/
Program.cs
54 lines (42 loc) · 1.44 KB
/
Program.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
using System;
namespace CommandPattern
{
internal static class Program
{
private static void Main()
{
var remote = new RemoteControl(3);
var bike = new Garage("Bike");
var bikeDoorClose = new GarageDoorCloseCommand(bike);
var bikeDoorOpen = new GarageDoorOpenCommand(bike);
var car = new Garage("Car");
var carDoorClose = new GarageDoorCloseCommand(car);
var carDoorOpen = new GarageDoorOpenCommand(car);
var garageButton = new OnOffStruct
{
On = bikeDoorOpen,
Off = bikeDoorClose
};
remote[0] = garageButton;
remote.PushOn(0);
remote.PushUndo();
remote.PushUndo();
remote.PushOff(0);
Console.WriteLine();
var light = new Light("Hall");
ICommand[] partyOn = { new LightOffCommand(light), bikeDoorOpen, carDoorOpen };
ICommand[] partyOff = { new LightOnCommand(light), bikeDoorClose, carDoorClose };
remote[2] = new OnOffStruct { On = new MacroCommand(partyOn), Off = new MacroCommand(partyOff) };
try
{
remote.PushOn(2);
Console.WriteLine();
remote.PushOff(2);
}
catch (Exception)
{
Console.WriteLine("Oops");
}
}
}
}