Is Eventbus a Mediator or Observer Pattern?

前端 未结 5 1632
面向向阳花
面向向阳花 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 20:00

    I'd say that a typical event bus utilises both of these patterns:

    • event bus essentially encapsulates how other objects communicate, so it is a mediator
    • objects that register as event handlers/listeners are observers (and the subjects of their observations are event types and/or objects that produce these events, not the bus itself), so as wikipedia says observer pattern "is mainly used to implement distributed event handling systems" (emphasis mine), but an event bus is not an observer per se.

提交回复
热议问题