This module explores different behavioral design patterns, patterns that describe the way objects and classes interact and divide responsibilities among themselves.
A behavioral pattern abstracts an action you want to take from the object or class that takes the action.
By changing the object or class, you can change the algorithm used, the objects affected, or the behavior, while still retaining the same basic interface for client classes.
A good toolbox of behavioral patterns allows you to solve many challenging problems you are likely to encounter when designing
object-oriented systems. These include enumerating lists, responding to changes of state in an object,
serializing and deserializing objects without penetrating data encapsulation.
Behavioral object patterns
use object composition rather than inheritance.
Some of these patterns describe how a group of peer objects cooperate to perform a task that no single object can carry out by itself.
An important issue here is how peer objects know about each other.
Peers could maintain explicit references to each other, but that would increase their coupling.
In the extreme, every object would know about every other.
pattern avoids this by introducing a
The mediator provides the indirection needed for loose coupling.
The Chain of Responsibility
provides even looser coupling
It lets you send requests to an object implicitly through a chain of candidate objects.
Any candidate may fulfill the request depending on run-time conditions.
The number of candidates is open-ended
, and you can select which candidates participate in the chain at run-time.