Chain of Responsibility
Explore how to implement the Chain of Responsibility pattern in Python to process event logs dynamically. Learn to chain event handlers so each tries to handle data or passes it along, enabling flexible, extensible, and maintainable event processing systems.
We'll cover the following...
Chain of responsibility is a behavioral pattern. We are going to take another look at our event systems. We want to parse information about the events that happened on the system from the log lines (text files, dumped from our HTTP application server, for example), and we want to extract this information in a convenient way.
Using the chain of responsibility pattern
Previously, we achieved an interesting solution that was compliant with the open/closed principle and relied on the use of the __subclasses__() magic method to discover all possible event types and process the data with the right event, ...