2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
The intention of the responsibility chain pattern in the design pattern is to decouple the sender and receiver of the request so that multiple objects have the opportunity to handle the request. These objects are connected into a chain and the request is passed along the chain until one object handles it.
For example, if an employee wants to claim reimbursement for travel expenses, he/she needs to upload the invoice, travel days, and destination. First, the person in charge of travel allowances in the finance department will review it and calculate the travel allowance according to regulations. Then, it will be approved by the department manager, department director, financial director, and others at each level.
The same is true for the chain of responsibility pattern. A request is sent and then processed by one object after another until the last object completes the processing and stops.
Handler: A transmitter interface that defines a request processing interface
ConcreteHandler: A specific handler that handles the request it is responsible for. It can access the next object in the chain and handle the request if it can, otherwise it forwards the request to the successor.
Client: The client application that makes the initial request to the object in the chain