Difference between Observer, Pub/Sub, and Data Binding

There are two major differences between Observer/Observable and Publisher/Subscriber patterns: Observer/Observable pattern is mostly implemented in a synchronous way, i.e. the observable calls the appropriate method of all its observers when some event occurs. The Publisher/Subscriber pattern is mostly implemented in an asynchronous way (using message queue). In the Observer/Observable pattern, the observers are aware … Read more

How can I update information in an Android Activity from a background Service

How can I set up my Activity to be listening to the Service? Is this the best way to approach this problem? You have three major options, as I see it: Polling. The Activity periodically asks the Service for the latest data. IMHO, this option sucks, but it’s certainly possible. Callbacks. Per jax’s answer, the … Read more

Is there a recommended way to use the Observer pattern in MVP using GWT?

Program Structure This is how I did it. The Eventbus lets presenters (extending the abstract class Subscriber) subscribe to events belonging to different modules in my app. Each module corresponds to a component in my system, and each module has an event type, a presenter, a handler, a view and a model. A presenter subscribing … Read more

Observer is deprecated in Java 9. What should we use instead of it?

Why is that? Does it mean that we shouldn’t implement observer pattern anymore? Answering the latter part first – YES, it does mean you shouldn’t implement Observer and Obervables anymore. Why were they deprecated – They didn’t provide a rich enough event model for applications. For example, they could support only the notion that something … Read more

Leveraging the observer pattern in JavaFX GUI design

As noted here, the JavaFX architecture tends to favor binding GUI elements via classes that implement the Observable interface. Toward this end, Irina Fedortsova has adapted the original Converter to JavaFX in Chapter 5 of JavaFX for Swing Developers: Implementing a Swing Application in JavaFX. I’ve recapitulated the program below, updating to Java 8 and … Read more

Super-simple example of C# observer/observable with delegates

The observer pattern is usually implemented with events. Here’s an example: using System; class Observable { public event EventHandler SomethingHappened; public void DoSomething() => SomethingHappened?.Invoke(this, EventArgs.Empty); } class Observer { public void HandleEvent(object sender, EventArgs args) { Console.WriteLine(“Something happened to ” + sender); } } class Test { static void Main() { Observable observable = … Read more

tech