Mixing the Template Method and Chain of Responsibility patterns
This section explores a combination of two powerful design patterns: the Template Method and the Chain of Responsibility. As we are about to explore, those two patterns fit together well.
We use the Template Method pattern as the base structure, providing the handlers’ blueprint. Meanwhile, the Chain of Responsibility pattern manages the handling sequence, ensuring each request is routed to the correct handler.
When these two patterns work in tandem, they form a robust framework that facilitates easy management, maintains order, and increases the adaptability of our system.
Project – Improved message interpreter
Now that we know both the Chain of Responsibility and Template Method patterns, it is time to DRY out our handlers by extracting the shared logic into an abstract base class using the Template Method pattern and providing extension points to the subclasses.
We covered...