Behavioral design patterns are design patterns that identify common communication patterns among objects. By doing so, these patterns increase flexibility in carrying out communication.
In these design patterns, the interaction between the objects should be in such a way that they can easily talk to each other and still should be loosely coupled.
That means the implementation and the client should be loosely coupled in order to avoid hard coding and dependencies.
There are 10 types of behavioral design patterns:
Chain of Responsibility consists of a source of command objects and a series of processing objects. It lets you pass requests along a chain of processing objects. Upon receiving a request, each processing object decides either to process the request or to pass it to the next one in the chain. This pattern solves:
- Coupling the sender of a request to its receiver should be avoided.
- It should be possible that more than one receiver can handle a request.
Code Example: