Design Mode learning Summary (23) intermediary Mode

Source: Internet
Author: User

This series mainly records what the design pattern intends to be, what issues it wants to solve, and when it can be used; how it solves it, and master its structure diagram, remember its key code. You can think of at least two of its application instances, one in life and one in software. What are the advantages and disadvantages of this model and what use cases are there, what should I pay attention to when using it.

Respect the author. For reposted, please indicate the blog of Xiaoyang.Http://blog.csdn.net/hacke2


23. intermediary Mode


Intention: An intermediary object is used to encapsulate a series of object interactions. The intermediary makes the objects do not need to be explicitly referenced to each other, so that the coupling is loose, and can independently change the interaction between them.
Main Solution: There are a lot of associations between objects, which will inevitably lead to a very complex structure of the system. If an object changes at the same time, we also need to track the objects associated with them and make corresponding processing at the same time.
When to use: Multiple classes are coupled to form a mesh structure.
Solution: Separate the above mesh structure into a star Structure
Structure chart:

Key code: Communication between object colleags is encapsulated into a class for separate processing
Application Instance: 1. China has added the WTO. Previously, various countries have trade with each other and the structure is complex. Now, various countries have trade with each other through the WTO. 2. airport scheduling system. 3. MVC framework, among which C (Controller) is the intermediary between m and V.
Strengths: 1. Reduces the complexity of the class and converts one-to-many to one-to-one. 2. decoupling between classes. 3. conforms to the Demeter principle.
Disadvantages: 1. Large intermediaries become complicated and difficult to maintain
Use Cases: 1. There are reference relationships between objects in the system that are more complex than references, leading to chaotic dependency structures between objects and difficulty in reusing the objects.
2. You want to encapsulate the behavior of multiple classes through an intermediate class, but do not want to generate too many child classes.
Notes: Should not be used in the case of chaotic duties

Design Mode learning Summary (23) intermediary Mode

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.