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.