Design Model: intermediary model learning and understanding, design model intermediary Model
Mediator Pattern is used to reduce the complexity of communication between multiple objects and classes. This mode provides an intermediary class that usually processes communication between different classes and supports loose coupling to make the code easy to maintain. The intermediary mode is a behavior mode.
Intent: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 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 preceding mesh into a star structure.
In the past few days, our company has a project involving this part. The municipal special equipment inspection agencies have their own inspectors. However, due to various reasons, there are often insufficient inspectors in some cities, at this time, you can borrow from other cities, but this loan has a fixed object and scope.
Suppose in Henan province, if there are fewer than 225 inspectors in Anyang, they can be transferred from Jiaozuo. If there are fewer than 215 inspectors in Luoyang, they can be transferred from Anyang. If there are fewer than 235 inspectors in Jiaozuo, they can be transferred from Luoyang, this is just a simulation requirement. Do not take it seriously...