[Big talk design model] -- Behavior Model Summary (one-to-many); big talk Design Model

Source: Internet
Author: User

[Big talk design model] -- Behavior Model Summary (one-to-many); big talk Design Model

Based on the classification of the previous blog, this blog summarizes the one-to-many relationship: responsibility chain, intermediary, observer, iterator. In fact, there is nothing to do with these models, and there is nothing to compare. I just put them together.


1. Chain of responsibility)
1. Official explanation
So that multiple objects have the opportunity to process requests, so as to avoid coupling between request senders and recipients. Connect the object to a chain and pass the request along the chain until an object processes it.

2. Class Diagram




3. Personal Understanding
Speaking of the responsibility chain, I think of the regulations on asking for leave for higher education. If you have less than two hours, you can ask for leave from the Commission for Discipline Inspection. If you have more than two hours, you have to ask for leave from teacher mi; the responsibility chain mode should also be used when computer fees are calculated by the data center charging system. Of course, you can also use the policy mode and refund.
2. Mediator)
1. Official explanation
An intermediary object is used to encapsulate a series of object interactions. The intermediary allows each object to reference each other without being displayed, so that the coupling is loose and the relationship between them can be changed independently.

2. Class Diagram


3. Personal Understanding
An intermediary is a mediator. For example, if two friends are in conflict, I need to resolve the conflict and send a message. These two friends do not directly communicate with each other and pass information through me.
3. Observer)
1. Official explanation
Defines a one-to-many dependency, allowing multiple observer objects to listen to a topic object at the same time. When the status of this topic object changes, it notifies all observer objects so that they can automatically update themselves.

2. Class Diagram


3. I personally understand the observer. This is an example everywhere around me. This reminds me of the fact that when I was in high school, we used multimedia film (ghost film ~~) for Class evening study ~~), The student's office will check and study at night. Generally, there will be a person who will report to us, but if this person doesn't, then the student's office will directly notify us, and there will be an abstract notification. However, we are often notified by the student office in person, waiting for the class teacher to get angry.
Iv. Iterator)
1. Official explanation
Provides a method to access each element in an aggregate object sequentially without exposing the internal representation of the object.

2. Class Diagram


3. Personal Understanding
The school committee assigns assignments to the teachers according to their student ID. The teachers can determine assignments from the past or from the later. The most important thing is that each assignment is completed, it will not drop the homework of any student. This is equivalent to an iterator mode!

V. Summary
It is easy to map models to real life, but it is difficult to map models from real life. I want to determine which mode is used. In the end, I still haven't learned enough. I can't hold a fat man in one breath. I just want to learn it this time. I will learn it many times later!

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.