Responsibility chain mode: Enables more than one object to have the opportunity to handle a request
Characteristics:
- Each object in the chain contains a reference to its next object and a way to handle the event. The request is passed on this chain until an object on the chain decides to process the request
- The client making this request does not know which object on the chain is ultimately processing the request, decoupling the sender of the request from the receiver
- Can dynamically change the order of processing object members, can dynamically increase the reduction of processing objects
Use:
- More for Windows systems, handling events such as mouse keyboards
Disadvantages:
- There is no guarantee that the request will be executed
- Not easy to observe the runtime features, which hinder the troubleshooting
Example:
Different types of messages are handled differently, the customer passes the message to the first processor, and the processor decides 1. Process the message; 2. Pass a reference to the same base class to the next processor
Responsibility chain Model--headfirst Design Patterns Learning Notes