Figure 9-5 shows an example of a moderation panel from a mailing list program. The program has trapped a message as potential spam and is asking for confirmation and further action. One of the allowable actions is to automatically reject any future emails from that address.
Figure 9-5. Mediator pattern illustration—mailing list moderation
Clearly, the moderation process here is performing part of the role of the Mediator pattern: establishing a communication protocol and content filter. The other part— keeping members unaware of each other—is inherently part of the mailing list concept of mailing to a central address and then broadcasting from there.
Design Now, let’s consider the Mediator pattern at the UML diagram level. As illustrated in Figure 9-6, it consists of only two classes that use messages to communicate: Colleague
Registers with a Mediator by supplying a Receive method; issues Send requests to other colleagues via the Mediator Mediator
Broadcasts sent messages to all signed-on Colleagues using the Respond delegate Colleague –mediator +Receive( ) +Send( )
send calls mediator Send
Mediator –Respond( ) : Callback +Send( ) +SignOn(Callback)
Respond calls Receive back
Figure 9-6. Mediator pattern UML diagram Mediator Pattern |
201