Abstract Interface Observer in Java

digitization, transformation, binary
Spread the love

Abstract interface Observer in Java

The Observer interface is used to implement the view portion of the model-view paradigm. The idea is that an Observable object, the model, represents some data that is being manipulated through a user interface, while Observer objects provide the user with a view of the data. When the Observable object is modified, it tells the Observer objects that the model has been modified by calling notifyObservers().

An Observer object registers with an Observable object to receive notifications when the Observable is modified. The Observer object is then notified of changes via the update() method.

The Observer interface defines the update() method required for an object to observe subclasses of Observable. An Observer registers interest in an Observable() by calling the Observable.addObserver() method.

Observer objects that have been registered in this way will have their update() method invoked by the Observable when that object has changed.

The structure of the interface Observer is given as

public abstract interface java.util.Observer{
// Public Instance Methods
public abstract void update(Observable o, Object arg);

The details of the class structure are given as follows:

public abstract void update(Observable o, Object arg);

public abstract void update(Observable o, Object arg) method is called to indicate that the data in the model implemented by the specified Observable object has been modified. The arg parameter is used to communicate changed information from the model to its view.
This “hint” object can be used to efficiently update the views of a model. For example, an Observable object could represent satellite image data.

READ  How To Set Classpath in Java

A set of Observer objects would provide different graphical views of the data. If the model data changed, the arg object would describe the part of the data that changed, and the Observer views could use this “hint” to update only parts of their displays.

o – The object that has been changed.
arg – A “hint” object that describes the change.

Spread the love
I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on ani01104@gamil.com


Please enter your comment!
Please enter your name here