Mediator/EventAggregator differences

戏子无情 提交于 2020-08-03 03:48:10

问题


Also, when i need to communicate between loosely coupled objects (for example, MVVM's ViewModel's), different books and blogs about best programming practices suggest use Mediator/EventAggregator patterns. My question is about differences/relations between those patterns. Can anyone describe them for me?


回答1:


The two are mostly used for the same reason; reducing coupling between classes. I have even seen implementations of both, doing exactly the same thing, namely passing information as a middleman from one object to another, without them knowing about each other.

However, (my interpretation is that) the difference lies in how the Mediator (should) encapsulate behavior, i.e. complex communication between objects, while an EventAggregator/MessageBus simply enables objects to subscribe to/publish events/messages without knowing who sent or will receive it.



来源:https://stackoverflow.com/questions/14456429/mediator-eventaggregator-differences

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!