Professional Documents
Culture Documents
Software Design
Lecture : 43
2
OR
Encapsulating Invocation
3
INVOKER
Receiver
The set of objects that actually contain the
implementation to offer the services required for
the request processing can be referred to as
Receiver objects as shown in the next slide.
8
9
if (RequestType=TypeA)
{
//do something
}
if (RequestType=TypeB)
{
//do something
}
12
Suggested Solution
The invoker that issues a request on behalf of the client
and the set of service-rendering Receiver objects can be
decoupled.
ii. An object-oriented callback
14
Command Object
The Command pattern suggests creating an abstraction
for the processing to be carried out or the action to be
taken in response to client requests
Class Diagram
19
20
Working of Client:
Flow of Application
i. Command object encapsulate a request by binding
together a set of actions on a specific receiver by
exposing a execute method.
ii. When execute method is called it causes the actions to
be invoked on a receiver
iii. From outside no other object know which action will be
executed against a receiver
iv. They just know if they will call execute method their
request will be served
25
Example
26
Hot Spots
i. The main advantage of the command design pattern is
that it decouples the object that invokes the operation
from the one that know how to perform it. And this
advantage must be kept.
ii. There are implementations of this design pattern in which
the invoker is aware of the concrete commands classes.
This is wrong making the implementation more tightly
coupled. The invoker should be aware only about the
abstract command class.