Skip to content

Commit dd9d627

Browse files
committed
Simplify examples and little fixes
1 parent 82bf829 commit dd9d627

File tree

10 files changed

+64
-118
lines changed

10 files changed

+64
-118
lines changed

Builder.Conceptual/Program.cs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,18 @@ public void buildFullFeaturedProduct()
186186
}
187187
}
188188

189-
public class Client
189+
class Program
190190
{
191-
// EN: The client code creates a builder object, passes it to the
192-
// director and then initiates the construction process. The end result
193-
// is retrieved from the builder object.
194-
//
195-
// RU: Клиентский код создаёт объект-строитель, передаёт его директору,
196-
// а затем инициирует процесс построения. Конечный результат
197-
// извлекается из объекта-строителя.
198-
public static void ClientCode(Director director)
191+
static void Main(string[] args)
199192
{
193+
// EN: The client code creates a builder object, passes it to the director and
194+
// then initiates the construction process. The end result is retrieved from the
195+
// builder object.
196+
//
197+
// RU: Клиентский код создаёт объект-строитель, передаёт его директору, а затем
198+
// инициирует процесс построения. Конечный результат извлекается из
199+
// объекта-строителя.
200+
var director = new Director();
200201
var builder = new ConcreteBuilder();
201202
director.Builder = builder;
202203

@@ -219,12 +220,4 @@ public static void ClientCode(Director director)
219220
Console.Write(builder.GetProduct().ListParts());
220221
}
221222
}
222-
223-
class Program
224-
{
225-
static void Main(string[] args)
226-
{
227-
Client.ClientCode(new Director());
228-
}
229-
}
230223
}

Flyweight.Conceptual/Program.cs

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -133,28 +133,10 @@ public class Car
133133

134134
public string Color { get; set; }
135135
}
136-
137-
public class Client
136+
137+
class Program
138138
{
139-
public void addCarToPoliceDatabase(FlyweightFactory factory, Car car)
140-
{
141-
Console.WriteLine("\nClient: Adding a car to database.");
142-
143-
var flyweight = factory.GetFlyweight(new Car {
144-
Color = car.Color,
145-
Model = car.Model,
146-
Company = car.Company
147-
});
148-
149-
// EN: The client code either stores or calculates extrinsic state
150-
// and passes it to the flyweight's methods.
151-
//
152-
// RU: Клиентский код либо сохраняет, либо вычисляет внешнее
153-
// состояние и передает его методам легковеса.
154-
flyweight.Operation(car);
155-
}
156-
157-
public static void ClientCode()
139+
static void Main(string[] args)
158140
{
159141
// EN: The client code usually creates a bunch of pre-populated
160142
// flyweights in the initialization stage of the application.
@@ -188,13 +170,23 @@ public static void ClientCode()
188170

189171
factory.listFlyweights();
190172
}
191-
}
192-
193-
class Program
194-
{
195-
static void Main(string[] args)
173+
174+
public void addCarToPoliceDatabase(FlyweightFactory factory, Car car)
196175
{
197-
Client.ClientCode();
176+
Console.WriteLine("\nClient: Adding a car to database.");
177+
178+
var flyweight = factory.GetFlyweight(new Car {
179+
Color = car.Color,
180+
Model = car.Model,
181+
Company = car.Company
182+
});
183+
184+
// EN: The client code either stores or calculates extrinsic state
185+
// and passes it to the flyweight's methods.
186+
//
187+
// RU: Клиентский код либо сохраняет, либо вычисляет внешнее
188+
// состояние и передает его методам легковеса.
189+
flyweight.Operation(car);
198190
}
199191
}
200192
}

Iterator.Conceptual/Program.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ public override IEnumerator GetEnumerator()
143143
}
144144
}
145145

146-
public class Client
146+
class Program
147147
{
148-
public void ClientCode()
148+
static void Main(string[] args)
149149
{
150150
// EN: The client code may or may not know about the Concrete
151151
// Iterator or Collection classes, depending on the level of
@@ -176,12 +176,4 @@ public void ClientCode()
176176
}
177177
}
178178
}
179-
180-
class Program
181-
{
182-
public static void Main(string[] args)
183-
{
184-
Client.ClientCode();
185-
}
186-
}
187179
}

Mediator.Conceptual/Program.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ public void DoD()
122122
this._mediator.Notify(this, "D");
123123
}
124124
}
125-
126-
class Client
125+
126+
class Program
127127
{
128-
public static void ClientCode()
128+
static void Main(string[] args)
129129
{
130130
// EN: The client code.
131131
//
@@ -143,12 +143,4 @@ public static void ClientCode()
143143
component2.DoD();
144144
}
145145
}
146-
147-
class Program
148-
{
149-
static void Main(string[] args)
150-
{
151-
Client.ClientCode();
152-
}
153-
}
154146
}

Memento.Conceptual/Program.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,10 @@ public void ShowHistory()
208208
}
209209
}
210210
}
211-
212-
class Client
211+
212+
class Program
213213
{
214-
public static void ClientCode()
214+
static void Main(string[] args)
215215
{
216216
// EN: Client code.
217217
//
@@ -240,12 +240,4 @@ public static void ClientCode()
240240
Console.WriteLine();
241241
}
242242
}
243-
244-
class Program
245-
{
246-
static void Main(string[] args)
247-
{
248-
Client.ClientCode();
249-
}
250-
}
251243
}

Observer.Conceptual/Program.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ public void Update(ISubject subject)
150150
}
151151
}
152152
}
153-
154-
class Client
153+
154+
class Program
155155
{
156-
public static void ClientCode()
156+
static void Main(string[] args)
157157
{
158158
// EN: The client code.
159159
//
@@ -173,12 +173,4 @@ public static void ClientCode()
173173
subject.SomeBusinessLogic();
174174
}
175175
}
176-
177-
class Program
178-
{
179-
static void Main(string[] args)
180-
{
181-
Client.ClientCode();
182-
}
183-
}
184176
}

Proxy.Conceptual/Program.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,26 @@ public void LogAccess()
9595

9696
public class Client
9797
{
98+
// EN: The client code is supposed to work with all objects (both
99+
// subjects and proxies) via the Subject interface in order to support
100+
// both real subjects and proxies. In real life, however, clients mostly
101+
// work with their real subjects directly. In this case, to implement
102+
// the pattern more easily, you can extend your proxy from the real
103+
// subject's class.
104+
//
105+
// RU: Клиентский код должен работать со всеми объектами (как с
106+
// реальными, так и заместителями) через интерфейс Субъекта, чтобы
107+
// поддерживать как реальные субъекты, так и заместителей. В реальной
108+
// жизни, однако, клиенты в основном работают с реальными субъектами
109+
// напрямую. В этом случае, для более простой реализации паттерна, можно
110+
// расширить заместителя из класса реального субъекта.
98111
public void ClientCode(ISubject subject)
99112
{
113+
// ...
114+
100115
subject.Request();
116+
117+
// ...
101118
}
102119
}
103120

Singleton.Conceptual/Program.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ public static Singleton getInstance()
4343
}
4444
}
4545
}
46-
47-
class Client
46+
47+
class Program
4848
{
49-
public static void ClientCode()
49+
static void Main(string[] args)
5050
{
5151
// EN: The client code.
5252
//
@@ -64,12 +64,4 @@ public static void ClientCode()
6464
}
6565
}
6666
}
67-
68-
class Program
69-
{
70-
static void Main(string[] args)
71-
{
72-
Client.ClientCode();
73-
}
74-
}
7567
}

State.Conceptual/Program.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ public override void Handle2()
115115
}
116116
}
117117

118-
class Client
118+
class Program
119119
{
120-
public static void ClientCode()
120+
static void Main(string[] args)
121121
{
122122
// EN: The client code.
123123
//
@@ -127,12 +127,4 @@ public static void ClientCode()
127127
context.Request2();
128128
}
129129
}
130-
131-
class Program
132-
{
133-
static void Main(string[] args)
134-
{
135-
Client.ClientCode();
136-
}
137-
}
138130
}

Strategy.Conceptual/Program.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ public object DoAlgorithm(object data)
116116
}
117117
}
118118

119-
class Client
119+
class Program
120120
{
121-
public static void ClientCode()
121+
static void Main(string[] args)
122122
{
123123
// EN: The client code picks a concrete strategy and passes it to
124124
// the context. The client should be aware of the differences
@@ -140,12 +140,4 @@ public static void ClientCode()
140140
context.DoSomeBusinessLogic();
141141
}
142142
}
143-
144-
class Program
145-
{
146-
static void Main(string[] args)
147-
{
148-
Client.ClientCode();
149-
}
150-
}
151143
}

0 commit comments

Comments
 (0)