Design Pattern _ responsibility chain pattern

Source: Internet
Author: User

Image example:

I went to the English class at night and sat down in the last row for good convenience. Wow, I sat in front of several beautiful mm. I found a piece of paper and wrote "Hi, can I be my girlfriend? If you don't want to, please pass it to the front. The paper is uploaded one by one. Unfortunately, the mm in the first row passed the paper to the teacher. I heard it was an old virgin. Run fast.!

Responsibility Chain Mode:

In the responsibility chain mode, many objects are connected by each object's reference to its next home to form a chain. Requests are transmitted on this chain until an object on the chain decides to process this request. The customer does not know which object on the chain finally processes this request. The system can dynamically reorganize the chain and assign responsibility without affecting the client. The handler has two options: Take responsibility or push the responsibility to the next house. A request cannot be accepted by any receiving end object.

Purpose:
So that multiple objects have the opportunity to process the request, so as to avoid coupling between the request sender and the receiver. connect these objects into a chain and pass the request along the chain until an object processes it.

UML structure diagram:



Abstract base class:
1) handler: defines a request processing interface. In the figure, this interface is the handlerequset function. This class also has a pointer to the handler object, the object to be processed (if any ).

Resolution:
This mode connects the objects that can process a request in the form of a chain, so that these objects have the opportunity to process the request. for example, when I often see someone in the palace on TV, the eunuchs (who can handle a request) will call XX in turn... this continues until this person is found. the chainofrefresibility mode also processes requests. If a subsequent object can be processed, the request is sent to the subsequent object for processing. Otherwise, the request is processed by the user. this design decouples the request sender from the request handler. For example, the sender of the account does not know which eunuch will find the person he wants to find, just issue the command and then OK.

 

Design Pattern _ responsibility chain pattern

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.