abstract class Mediator public abstract void Send string msg Colleague

 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
abstract class Mediator
{
public abstract void Send(string msg, Colleague colleague);
}
abstract class Colleague
{
protected Mediator mediator;
public Colleague(Mediator mediator)
{
this.mediator = mediator;
}
}
class ConcreteColleague1 : Colleague
{
public ConcreteColleague1(Mediator mediator)
: base(mediator)
{ }
public void Send(string message)
{
mediator.Send(message, this);
}
public void Notify(string message)
{ }
}
class ConcreteColleague2 : Colleague
{
public ConcreteColleague2(Mediator mediator)
: base(mediator)
{ }
public void Send(string message)
{
mediator.Send(message, this);
}
public void Notify(string message)
{ }
}
class ConcreteMediator : Mediator
{
public ConcreteColleague1 Colleague1 { get; set; }
public ConcreteColleague2 Colleague2 { get; set; }
public override void Send(string msg, Colleague colleague)
{
if (Colleague1 == colleague)
Colleague2.Notify(msg);
else
Colleague1.Notify(msg);
}
}