-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
160 lines (149 loc) · 7.87 KB
/
Program.cs
File metadata and controls
160 lines (149 loc) · 7.87 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using DesignPatterns.AdapterDesignPattern;
using DesignPatterns.CommandDesignPattern;
using DesignPatterns.CommandDesignPattern.Commands;
using DesignPatterns.CommandDesignPattern.Recievers;
using DesignPatterns.DecoratorDesignPattern;
using DesignPatterns.DecoratorDesignPattern.Decorator;
using DesignPatterns.DecoratorDesignPattern.Interfaces;
using DesignPatterns.FacadeDesignPattern;
using DesignPatterns.FacadeDesignPattern.SubSystem;
using DesignPatterns.FactoryDesignPattern;
using DesignPatterns.ObserverDesignPattern;
using DesignPatterns.ObserverDesignPattern.Observers;
using DesignPatterns.StrategyDesignPattern;
using DesignPatterns.StrategyDesignPattern.FlyBehavior;
using DesignPatterns.StrategyDesignPattern.QuackBehavior;
using DesignPatterns.TemplateMethodDesignPattern.Example1;
namespace DesignPatterns
{
class Program
{
// Main method - entry point of the C# application
static void Main(string[] args)
{
Console.WriteLine("Welcome to Design Patterns World!!");
// 1. Strategy Design Pattern : Behavioral
// MallardDuck mallardDuck = new MallardDuck(new FlyWithWings(), new DuckQuack());
// mallardDuck.Display();
// mallardDuck.PerformFly();
// mallardDuck.PerformQuack();
// RubberDuck rubberDuck = new RubberDuck(new FlyNoWay(), new MuteQuack());
// rubberDuck.Display();
// rubberDuck.PerformFly();
// rubberDuck.PerformQuack();
//2. Observer Design Pattern : Behavioral
// WeatherData weatherData = new WeatherData();
// CurrentConditionsDisplay display = new CurrentConditionsDisplay(weatherData);
//StaticsDisplay display2 = new StaticsDisplay(weatherData); //not implemented
//ForecastDisplay display3 = new ForecastDisplay(weatherData); //not implemented
// weatherData.SetMeasurements(80, 65,30.4f);
// weatherData.SetMeasurements(85, 70,35.4f);
// weatherData.SetMeasurements(90, 75,40.4f);
// //3. Decorator Design Pattern : Structural
// IBeverage espresso = new Espresso();
// Console.WriteLine($"Beverage: {espresso.GetDescription()} & Cost: {espresso.Cost()}");
// espresso= new Milk(espresso);
// Console.WriteLine($"Beverage: {espresso.GetDescription()} & Cost: {espresso.Cost()}");
// espresso= new Mocha(espresso);
// Console.WriteLine($"Beverage: {espresso.GetDescription()} & Cost: {espresso.Cost()}");
//4. Factory Design Pattern : Creational
// PizzaStore pizzaStore = new NyPizzaStore();
// pizzaStore.OrderPizza("cheese");
// pizzaStore.OrderPizza("veggie");
// pizzaStore = new ChicagoPizzaStore();
// pizzaStore.OrderPizza("cheese");
// pizzaStore.OrderPizza("veggie");
//5. Singleton Design Pattern :
//6. Command Design Pattern
// //Simple Remote with one button
// SimpleRemoteControl simpleRemote = new SimpleRemoteControl();
// simpleRemote.SetCommand(new LightOnCommand(new Light()));
// Console.WriteLine(simpleRemote.ToString());
// simpleRemote.ButtonWasPressed();
// simpleRemote.SetCommand(new LightOffCommand(new Light()));
// Console.WriteLine(simpleRemote.ToString());
// simpleRemote.ButtonWasPressed();
//
// //Remote with Multiple buttons
// RemoteControl remoteControl = new RemoteControl();
// //Receivers
// Light livingRoomLight = new Light("Living Room Light");
// Light kitchenLight = new Light("Kitchen Light");
// CeilingFan ceilingFan = new CeilingFan("Living Room Fan");
// GarageDoor garageDoor = new GarageDoor();
// Stereo stereo = new Stereo("Living Room Stereo");
// //Commands
// LightOnCommand livingRoomLightOnCommand = new LightOnCommand(livingRoomLight);
// LightOffCommand livingRoomLightOffCommand = new LightOffCommand(livingRoomLight);
// LightOnCommand kitchenLightOnCommand = new LightOnCommand(kitchenLight);
// LightOffCommand kitchenLightOffCommand = new LightOffCommand(kitchenLight);
// CeilingFanOnCommand ceilingFanOnCommand = new CeilingFanOnCommand(ceilingFan);
// CeilingFanOffCommand ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFan);
// StereoOnWithCDCommand stereoOnWithCdCommand = new StereoOnWithCDCommand(stereo);
// StereoOffCommand stereoOffCommand = new StereoOffCommand(stereo);
// ICommand[] partyOnCommands = new ICommand[]
// {
// livingRoomLightOnCommand,
// ceilingFanOnCommand,
// stereoOnWithCdCommand
// };
// ICommand[] partyOffCommands = new ICommand[]
// {
// livingRoomLightOffCommand,
// ceilingFanOffCommand,
// stereoOffCommand
// };
// MacroCommand partyOnCommand = new MacroCommand(partyOnCommands);
// MacroCommand partyOffCommand = new MacroCommand(partyOffCommands);
//
// remoteControl.SetCommand(0,kitchenLightOnCommand, kitchenLightOffCommand);
// remoteControl.SetCommand(1,livingRoomLightOnCommand, livingRoomLightOffCommand);
// remoteControl.SetCommand(2,ceilingFanOnCommand, ceilingFanOffCommand);
// remoteControl.SetCommand(3,stereoOnWithCdCommand, stereoOffCommand);
// //Party Mode using MacroCommand
// remoteControl.SetCommand(4, partyOnCommand, partyOffCommand);
// Console.WriteLine(remoteControl.ToString());
// remoteControl.OnButtonPressed(0);
// //Undo Button
// remoteControl.UndoButtonPressed(0);
// remoteControl.OffButtonPressed(0);
// remoteControl.UndoButtonPressed(0);
// remoteControl.OnButtonPressed(1);
// remoteControl.OffButtonPressed(1);
// remoteControl.OnButtonPressed(2);
// remoteControl.OffButtonPressed(2);
// remoteControl.OnButtonPressed(3);
// remoteControl.OffButtonPressed(3);
// //Party mode
// remoteControl.OnButtonPressed(4);
// remoteControl.OffButtonPressed(4);
// remoteControl.UndoButtonPressed(4);
//7. Adapter Design Pattern
// DuckTestDrive duckTestDrie = new DuckTestDrive();
// duckTestDrie.DuckTest();
//8. Facade Design Pattern
// Amplifier amp = new Amplifier();
// DVDPlayer dvd = new DVDPlayer();
// Projector proj = new Projector();
// Lights lights = new Lights();
// Speakers speakers = new Speakers();
//
// HomeTheaterFacade homeTheater = new HomeTheaterFacade(amp, dvd, proj, lights, speakers);
//
// homeTheater.WatchMovie("Inception");
// homeTheater.EndMovie();
//9. Template Method Design Pattern
// Example 1 (Payment Processor)
// Console.WriteLine("Processing PayPal Payment:");
// PaymentProcessor paypal = new PayPalPayment();
// paypal.ProcessPayment(100);
//
// Console.WriteLine("\nProcessing Credit Card Payment:");
// PaymentProcessor creditCard = new CreditCardPayment();
// creditCard.ProcessPayment(250);
// Wait for the user to press a key before closing the console window
Console.WriteLine("\nPress any key to exit...");
Console.ReadKey();
}
}
}