Is Eventbus a Mediator or Observer Pattern?

前端 未结 5 1612
面向向阳花
面向向阳花 2021-01-01 19:11

Is Eventbus more a Mediator or an Observer? According to Google, \"eventbus mediator\" gets 2.430 hits and \"eventbus observer\" gets 3.850 hits.

From the descriptio

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-01 19:36

    wikipedia: The essence of the Mediator Pattern is to "Define an object that encapsulates how a set of objects interact"

    EventBus does not do this.

    EventBus is also not observer pattern because if you have N objects and you want to communicate between all of them you need N*N observers if you use the observer pattern but only one global EventBus is enough to do the same job.

    So EventBus is THE EventBus pattern.

提交回复
热议问题