Summary
In this chapter, we covered two GoF behavioral patterns. These patterns can help us create flexible yet easy-to-maintain systems. As the name suggests, behavioral patterns aim at encapsulating application behaviors into cohesive pieces.
First, we looked at the Template Method pattern, which allows us to encapsulate an algorithm’s outline inside a base class, leaving some parts open for modification by subclasses. Tricking code into doing your bidding instead of properly designing that part of the system leads to half-baked solutions that become hard to maintain.
The subclasses then fill in the gaps and extend that algorithm to those predefined locations. These locations can be required (abstract) or optional (virtual).
Then, you learned about 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 (the interface),...