"Design Mode Design Pattern" Reading Notes

xiaoxiao2021-03-06  20

"Design Mode Design Pattern" Reading Notes

Mediator mode

structure

purpose

In order to reduce the complexity of communicating between a large number of objects (colleague), create a middleman - Mediator (similar to HUB); this, each colleague only establishes the connection between Mediator without the need to directly connect directly to each colleague . Communication between each colleague is completely processed through MediaTor.

advantage

1, Mediator reduces the coupling between the colleague and improves the reuse of Colleague.

2, if you need to change the communication behavior between the colleague, you don't need to derive the colleague itself, you can complete it.

3. Use one-to-man relationship instead of MANY-TO-MANY, more simple and easy to understand, maintenance, and expansion.

Disadvantage

Mediator may become complicated.

discuss

1. Creating an Abstract Mediator is not required. If each colleague will only communicate with a Mediator, you don't need Abstract Mediator; however, Abstract Mediator is more flexible, you can derive a Mediator to change the communication behavior between Colleague.

2, the relationship between the one-to-port between MEDIATOR and the various colleague can be implemented using the Observer mode, so that after a colleague is updated, notify all Colleague through Mediator.

Reference

"Design Pattern" Gang-Of-4 1997

转载请注明原文地址:https://www.9cbs.com/read-42733.html

New Post(0)