Summary
In this chapter, we covered two GoF behavioral patterns. These patterns can help us create a flexible, yet easy-to-maintain system. As the name suggests, behavioral patterns aim at encapsulating application behaviors into cohesive software pieces.
First, we looked at the Template Method pattern, which allows us to encapsulate an algorithm’s core inside a base class. It then allows its subclasses to fill in the gaps and extend that algorithm at predefined locations. These locations can be required (abstract
) or optional (virtual
).
Then, we explored the Chain of Responsibility pattern, which opens the possibility of chaining multiple small handlers into a chain of processing, inputting the message to be processed at the beginning of the chain, and waiting for one or more handlers to execute the actual logic related to that message against it. That is an important nuance: you don’t have to stop the chain’s execution at the first handler. In some cases...