2. Introduction
Behavioral design pattern.
Uses a chain of objects to handle a request.
Objects in the chain forward the request along the
chain until one of the objects handles the request.
Avoid coupling the sender of a request to its receiver
by giving more than one object a chance to handle
the request.
3. Class Diagram
successor
client Handler
Request
handleRequest()
ConcreteHandler1 ConcreteHandler2
handleRequest() handleRequest()
4. Usage
Several objects have similar methods that could be
appropriate for the action that the program is
requesting.
One of the objects might be most suitable.
5. Usage (cont.…)
Having new objects that want to add to the list of
processing options while the program execution.
When more than one object may handle a request
and the actual handler is not know in advance
6. Implementation
In brief,
We create four objects that can either “Add”,
“Subtract”, “Multiply” or “Divide”.
Send two numbers and a command, that allow above
four objects to decide which can handle the
requested calculation.