- Design Patterns and Best Practices in Java
- Kamalmeet Singh Adrian Ianculescu LUCIAN PAUL TORJE
- 250字
- 2021-06-25 20:52:39
The mediator pattern
In many cases, when we design and develop software applications, we encounter many scenarios where we have modules and objects that have to communicate with one another. The easiest approach would be to make them in such a way that they know each other and can send messages directly.
However, this might create a mess. If we imagine, for example, a communication app in which each client has to connect to another one, it doesn't make sense for a client to manage many connections. A better solution would be to connect to a central server and for the server to manage the communication between the clients. The client sends the message to the server and the server keeps the connection active to all the clients, and it can broadcast messages to all required recipients.
Another example is where a specialized class is required to mediate between different controls, such as buttons, dropdowns, and list controls, in a graphical interface. For example, the graphical controls in a GUI can hold a reference to each other in order to invoke their methods reciprocally. But obviously, this will create an extremely coupled code in which each control depends on all the others. A better approach would be to make the parent responsible for broadcasting messages to all the required controls when something needs to be done. When something modifies in a control, it will notify the window, which will check which controls need to be informed and then inform them.
- JavaScript百煉成仙
- MySQL數(shù)據(jù)庫管理實戰(zhàn)
- 數(shù)據(jù)結(jié)構(gòu)和算法基礎(Java語言實現(xiàn))
- 區(qū)塊鏈架構(gòu)與實現(xiàn):Cosmos詳解
- SQL基礎教程(視頻教學版)
- Oracle從入門到精通(第5版)
- R Data Analysis Cookbook(Second Edition)
- C語言從入門到精通
- Java程序設計基礎(第6版)
- 數(shù)據(jù)分析與挖掘算法:Python實戰(zhàn)
- Visual C++從入門到精通(第2版)
- AI自動化測試:技術(shù)原理、平臺搭建與工程實踐
- 從零開始學Unity游戲開發(fā):場景+角色+腳本+交互+體驗+效果+發(fā)布
- Extending Docker
- Socket.IO Cookbook