Mediator Pattern

Role

The Mediator pattern is there to enable objects to communicate without knowing each other's identities. It also encapsulates a protocol that objects can follow.

Illustration

The Mediator pattern is all about communication. There are numerous ways of communicating these days. Communication can be between two individuals, or among members of a group. Often there is protocol that is observed between the members of a group. Messages might also be vetted for content. All of this points to the need for a mediator.

Consider a mailing list whose members are people interested in C# 3.0 Design Patterns. People interested in the topic can join the mailing list by subscribing to it using a special message subject ("Subscribe"). Any messages that come in will go to all of the list's subscribers. Members can remove themselves from the list at any time by sending an "Unsubscribe" message.

Of course, mailing lists are seldom so simple. Members expect that messages they receive will not be spam, will come only from other members, and will be relevant to the topic at hand. To enforce this latter rule, the cs3pd group might decide not to permit any messages that mention Java, for instance. Sending out messages and checking their content is termed "moderating" the list. Some of the moderation functionality can be handled by software, and some of it will be done by a designated person in the group (usually referred to as the moderator).

Figure 9-5 shows an example of a moderation panel ...

Get C# 3.0 Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.