Skip to content

EventDispatch implements the Mediator pattern, not the Observer pattern #2817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

johnkary
Copy link
Contributor

Anthony Ferrara @ircmaxell does a great job of pointing out the differences between the Mediator and Observer pattern in his blog post Handling Plugins In PHP.

The two patterns appear very similar but differ in which object does the event emitting:

An implementation of the Observer pattern would allow each object/entity/service to individually allow subscribing to its events and it would notify all listeners itself: OrderPersister->notify('order.create', $order)

But a Mediator pattern implementation would be like the Symfony EventDispatcher object that is centrally-configured with listeners and then notifies those listeners of events on behalf of its external collaborators: Inside a controller $this->persister->create($order); then inside Persister::create() -- $this->dispatcher->notify('order.create', $order)

🌊

@wouterj
Copy link
Member

wouterj commented Jul 11, 2013

This should be merged in 2.2, 2.0 and 2.1 are deprecated

@johnkary
Copy link
Contributor Author

@wouterj Should I open a new PR against 2.2?

@wouterj
Copy link
Member

wouterj commented Jul 12, 2013

No, we'll cherrypick the commit when merging. It's just a tip for the next time.

@weaverryan
Copy link
Member

Hey John!

Ah, thanks for the fix! In fact, we just had a talk at the Nashville PHP meetup about 2 weeks ago where this was also explained, and had the same thought there (though not with as much clarity as you explained). I've patched this into the 2.2 branch at sha: 5c0e52c

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants