Mediator Pattern Code Review
Use the Mediator Pattern
Code Review
- Mediator Pattern Code Review: Define the Mediator Object
- Mediator Pattern Code Review: Define the Colleague Objects
- Mediator Pattern Code Review: Use the Mediator Pattern
Code Walkthrough
The Program class creates the Mediator object and various Colleague objects.
class Program
{
static void Main(string[] args)
{
Mediator m = new Mediator();
Colleague head1 = new Colleague(m, "John"); ColleagueB branch1 = new ColleagueB(m, "David"); Colleague head2 = new Colleague(m, "Lucy");
head1.Send("Meeting on Tuesday, please all ack"); branch1.Send("Ack"); m.Block(branch1.Receive); head1.Send("Still awaiting some Acks"); head2.Send("Ack"); m.Unblock(branch1.Receive); head1.Send("Thanks all");
Console.Read(); } }
Colleague head1 = new Colleague(m, "John"); ColleagueB branch1 = new ColleagueB(m, "David"); Colleague head2 = new Colleague(m, "Lucy");
head1.Send("Meeting on Tuesday, please all ack"); branch1.Send("Ack"); m.Block(branch1.Receive); head1.Send("Still awaiting some Acks"); head2.Send("Ack"); m.Unblock(branch1.Receive); head1.Send("Thanks all");
Console.Read(); } }
Messages are then exchanged between the Colleague objects, through the Mediator object.
Printer Friendly Version
Add to Favourites
DotNet Kicks
Digg
del.icio.us
Live Favourites
ma.gnolia
reddit
Slashdot
Technorati
Yahoo!