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, master its structure diagram, remember its key code; be able to 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 scenarios are there, what should I pay attention to when using it.

 

 

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 they are loosely coupled, in addition, the interaction between them can be changed independently.
Main Solution: There are a lot of associations between objects, which will inevitably lead to complicated system structure. At the same time, if an object changes, we also need to track associated objects, 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 joined the WTO. Previously, various countries had trade with each other and the structure was complex. Now, various countries have trade with each other through the WTO. 2. airport scheduling system. 3. MVC framework, where C (Controller) is the intermediary between M and V.
Advantages: 1. Reduces the complexity of classes 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 complex reference relationships between objects in the system, resulting in chaotic dependency structures between them and difficulty in reusing the object.
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

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.