Is Eventbus a Mediator or Observer Pattern?

Stefan picture Stefan · May 12, 2011 · Viewed 8.7k times · Source

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 description, they would both match what I was trying to do (the mediator even a little more). So does eventbus implement a specific pattern or is it up to me which I say it is?

Answer

Cliff L. Biffle picture Cliff L. Biffle · Feb 14, 2012

Often, a given piece of code isn't intrinsically an example of one pattern or another. This is why they're called "patterns" (rather than, say, "implementation techniques"). A lot of software kinda looks like one pattern, but also resembles another -- this is good. It's best not to adhere to patterns for patterns' sake, but to use them as a shared vocabulary for discussing architecture.

EventBus is one such tool. I wrote it with Observer-like situations in mind, but if you structure your application appropriately it can play a Mediator-like role.