-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
91 lines (71 loc) · 2.85 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
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
using Patterns.BehaviouralPatterns.Command;
using Patterns.BehaviouralPatterns.Interpreter;
using Patterns.BehaviouralPatterns.Mediator;
using Patterns.GeneratingPatterns.AbstractFactory;
using Patterns.GeneratingPatterns.AbstractFactory.ConcreteFactories;
using Patterns.GeneratingPatterns.Builder;
using Patterns.GeneratingPatterns.Builder.ConcreteBuilders;
using Patterns.GeneratingPatterns.FactoryMethod;
using Patterns.GeneratingPatterns.FactoryMethod.Drawing;
using Patterns.GeneratingPatterns.Prototype;
namespace Patterns
{
class Program
{
static void Main(string[] args)
{
// Abstract factory
IFactory concreteFactory = new WindowsFactory();
var obj1 = concreteFactory.CreateCloneable();
var obj2 = concreteFactory.CreateComparable();
// Builder
IBuilder builder = new Builder1();
var director = new Director(builder);
var product = director.Construct<IProduct>();
// Factory method
Application app = new DrawingApplication();
Document document = app.CreateDocument();
// Prototype
Prototype prototype = new ConcretePrototype1();
Prototype newObject = prototype.Clone();
// Command
Receiver receiver = new Receiver();
Command command = new ConcreteCommand(receiver);
Invoker invoker = new Invoker();
invoker.SetCommand(command);
invoker.ExecuteCommand();
// Interpreter
var context = new Context();
AbstrcatExpression experssion1 = new NonterminalExpression();
AbstrcatExpression expression2 = new TerminalExpression();
experssion1.Interpret(context);
expression2.Interpret(context);
// Mediator
ConcreteMediator m = new ConcreteMediator();
ConcreteColleague1 c1 = new ConcreteColleague1(m);
ConcreteColleague2 c2 = new ConcreteColleague2(m);
m.Colleague1 = c1;
m.Colleague2 = c2;
c1.Send("How are you?");
c2.Send("Fine, thanks");
// Memoto
Originator o = new Originator();
o.State = "On";
// Store internal state
Caretaker c = new Caretaker();
c.Memento = o.CreateMemento();
// Continue changing originator
o.State = "Off";
// Restore saved state
o.SetMemento(c.Memento);
// Observer
ConcreteSubject s = new ConcreteSubject();
s.Attach(new ConcreteObserver(s, "X"));
s.Attach(new ConcreteObserver(s, "Y"));
s.Attach(new ConcreteObserver(s, "Z"));
// Change subject and notify observers
s.SubjectState = "ABC";
s.Notify();
}
}
}