Download presentation
1
BY VEDASHREE GOVINDA GOWDA
DESIGN PATTERNS BY VEDASHREE GOVINDA GOWDA
2
MEDIATOR Design PATTERN
Mediator pattern comes under behavioral pattern. It acts as a medium for communication in between two classes and defines an object that controls how a set of objects interact. We can use mediator pattern when the complexity of object communication begins to hinder object reusability. Loose coupling between colleague objects is achieved by having colleagues communicate with the Mediator, rather than with each other
3
MEDIATOR Design PATTERN
In a mediator design pattern implementation we will have Mediator interface – an interface that defines the communication rules between objects Concrete mediator – a mediator object which will enables communication between participating objects Colleague – objects communicating with each other through mediator object
4
Class DIAGRAM
5
ADVANTAGES AND DISADVANTAGES
Comprehension : Hides all coordination activites and therefore user is better able to understand the system Decoupled colleagues : colleagues can be added/removed/modified easier as they depend less on each other. Ease of protocols : the one-to-many relationship of the mediator is much preferred to over the many-to-many relationship among colleagues. Limits subclassing : Only the mediator needs subclassing when changing behavior; the colleagues can remain the same. Complexity: because the mediator may handle a potentially large number of colleagues, the contents of the mediator may be very complex Disadvantages
6
Differentiate between mediator and observer
There is usually one mediator per pattern (or constraint) All the response actions are stored in the mediator The mediator may modify states of the concrete colleagues This pattern may implicitly use the observer pattern Observer distributes communication by introducing "observer" and "subject" objects. There might be multiple observers Each observer knows how to query the state change in its subject
7
command PATTERN When do we use command pattern?
When we need to issue requests to objects without knowing anything about the operation being requested or the receiver of the request. Command design pattern provides the options to queue commands, undo/redo actions and other manipulations. This is a behavioural pattern as it defines a manner for controlling communication between classes or entities. The command pattern is used to express a request, including the call to be made and all of its required parameters, in a command object. The command may then be executed immediately or held for later use. Often a queue of commands will be created that can be executed in a batch.
8
command PATTERN The command object does not contain the functionality that is to be executed, only the information required to perform an action. The functionality is contained within receiver objects. This removes the direct link between the command definitions and the functionality, promoting loose coupling. Neither of these object types is responsible for determining the time of execution of the command. This is controlled using an invoker.
9
command PATTERN The classes participating in the pattern are: Command - Declares an interface for executing an operation; Concrete Command - Extends the Command interface, implementing the Execute method by invoking the corresponding operations on Receiver. It defines a link between the Receiver and the action. Client - Creates a ConcreteCommand object and sets its receiver Invoker - Asks the command to carry out the request Receiver - Knows how to perform the operations
10
command PATTERN
12
THANK YOU
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.