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.
You can use PropertyChangeEvent and PropertyChangeListener from java. beans package. PropertyChangeListener replaces Observer , but what should I extend/implement in place of Observable ?
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.
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.
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.
How about Message Queue?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With