All About Class Observable in Java

0
20
Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

 

All About Class Observable in Java Example
Observable in Java

Observable in Java:

All About Class Observable in java represents an Observable object or data in the model view framework, therefore it is the super class of all observable objects.

This class can be sub classed to represent an object that the application wants to have observed.

All About Class Observable in Java

Basically an Observable object can have one or more observers. After an Observable instance changes, an application calling the observable’s notify observer’s method.

Causing all of its observers to be notified of the changes by a call to their update method. It maintain an internal flag called “changed.”

To set and clear which may be queried by has Changed by another observer.

The Observable and Observer objects play an important role in implementing Model-View-Controller architecture in Java.

They are typically used in a system where one object needs to notify another about the occurrences of some important changes.

Observable is a class and Observer is an interface. Hence they are found in the java.util package as a part of the Java Core Utility Framework. However, the Observable entity found in the JavaFX is an interface and is a part of the javaf.beans package.

The basic idea is the same, yet the implementation varies.

This article shall try to explain the concepts behind the paradigm and how they are used in Java code

The class Observable is defined as below:

 


public class java.util.Observable extends java.lang.Object{
//constructor
public Observable();
//Methods
public synchronized void addObserver(Observer observer);
public synchronized void deleteObserver(Observer observer);
public synchronized void deleteObservers();
public void notifyObservers();
public void notifyObserver(Observer obj);
public synchronized boolean hasChanged();
public synchronized int countObservers();
protected synchronized void clearChanged();
protected synchronized void setChanged();
}
 

 

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

LEAVE A REPLY

Please enter your comment!
Please enter your name here