class Client void Main Handler h1 new ConcreteHandler1 Handler h2 new

 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
class Client
{
void Main()
{
Handler h1 = new ConcreteHandler1();
Handler h2 = new ConcreteHandler2();
h1.Successor = h2;
h1.HandleRequest(2);
}
}
abstract class Handler
{
public Handler Successor { get; set; }
public abstract void HandleRequest(int condition);
}
class ConcreteHandler1 : Handler
{
public override void HandleRequest(int condition)
{
if (condition == 1)
{
// обработка;
}
else if (Successor != null)
{
Successor.HandleRequest(condition);
}
}
}
class ConcreteHandler2 : Handler
{
public override void HandleRequest(int condition)
{
if (condition==2)
{
// обработка;
}
else if (Successor != null)
{
Successor.HandleRequest(condition);
}
}
}