Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to Observer Pattern

Does anyone know of an alternative to the Observer a.k.a. Listener pattern? I'm interested in something that would work well in an asynchronous environment.

The problem I'm facing is that I have an application which uses this pattern a lot, which is not a bad thing per se, but it becomes a bottleneck as the number of listeners increases. Combined with threading primitives (mutexes, critical sections - of course in my specific environment) the hit on performance is really bad.

like image 708
celavek Avatar asked Mar 02 '11 15:03

celavek


People also ask

What can I use instead of Observer in Java?

You can use PropertyChangeEvent and PropertyChangeListener from java. beans package. PropertyChangeListener replaces Observer , but what should I extend/implement in place of Observable ?

What is another name for the observer design pattern?

For an Observable object, we use the term Subject. Objects that are subscribed to the Subject's changes are called Observers. A Subject and Observers are typically in one-to-many dependency. The Observer Design Pattern is also known as the Event-Subscriber or the Listener pattern.

What is a difference between the mediator pattern and the Observer pattern?

Mediator and Observer are competing patterns. The difference between them is that Observer distributes communication by introducing "observer" and "subject" objects, whereas a Mediator object encapsulates the communication between other objects.

Is Observer pattern same as pub sub?

In the observer pattern, the observers are aware of the Subject . The Subject maintains a record of the Observers . Whereas, in publisher-subscriber, publishers and subscribers don't need to know each other. They simply communicate with the help of message queues or a broker.


1 Answers

How about Message Queue?

like image 186
yegor256 Avatar answered Nov 05 '22 02:11

yegor256