Chapter 4. Behavioral Patterns
In the preceding chapters, we discussed how we can create objects or structure our code to enhance its modularity and reusability. This chapter focuses on design patterns to enable communication between objects and keep them loosely coupled at the same time.
Introducing these design patterns in code increases their flexibility and reusability in order to carry out the communication between objects. It mostly focuses on how an object interacts and how responsibilities are shared amongst them.
We should consider using behavioral patterns in the following scenarios:
- Passing same request to multiple handlers
- Implementing object-oriented callbacks
- Persisting and recovering the state of an object
- Parsing languages or defined scripts
- Sending a state notification to multiple recipients
- Defining a family of algorithms and using them interchangeably
In this chapter, we will discuss the following design patterns:
- The chain of responsibility pattern
- The...