All Talk: Using the Mediator Pattern in .NET Framework -- Visual Studio Magazine
The mediator pattern is a common software design pattern that allows two classes to communicate without knowing about each other. What happens is that the two classes communicate via a mediator class and are only aware of the mediator. It's use becomes evident when the number of objects in your apps starts to grow and management of the classes starts to become unwieldy.
The core components of the mediator pattern are the mediator interface, the concrete mediator and the colleague classes. The mediator interface defines the contract by which the two colleague classes will communicate. The concrete mediator implements the mediator interface. And the colleague classes use the mediator interface to communicate. In a sense, the mediator class acts as a message bus between colleague classes.
To demonstrate the mediator pattern I'll create a simple Windows Store app that allows a user to send a message to one or many parties. The user will be able to register multiple users to the chatroom, then select from and to users for the message.
First, I add the IUser colleague interface. The IUser interface stores a chat user's name and messages. Furthermore, the interface allows a user to send and receive chat messages and it has an IChatroom instance:
Read full article from All Talk: Using the Mediator Pattern in .NET Framework -- Visual Studio Magazine
No comments:
Post a Comment