How are Observer and Observable used?

How are Observer and Observable used?

The observer pattern in java is known for its use in design. Whenever an observable object changes its state, its corresponding observer classes are notified. Observable is implemented as a class which includes methods for managing Observer lists and notifying Observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. For example, third-party software cannot be made Observable without changing an existing class hierarchy.

How are Observer and Observable used?

The Java programming language provides support for the MVC architecture with two classes:

Observer: object that wants to be notified when the state of another object changes

Observable: Object whose state is of interest to another object.

These two classes are suitable for a system in which objects need to be automatically notified of changes that occur in other objects.

They provide the mechanism by which the views can be automatically notified of changes in the model.

How are Observer and Observable used?

The observable class represents an observable object.

The object to be observed can be represented by sub-classing observable class.

When there is a change in an observable instance, an application calling the Observable's notifyObservers method causes all of its observers to be notified of the change by a call to their update method.
Difference between a break statement and a continue statement
Difference between a break statement and a continue statement - A break statement when applied to a loop ends the statement. A continue statement ends the iteration of the.......
What are synchronized methods and synchronized statements?
What are synchronized methods and synchronized statements? - Synchronization does not allow invocation of this Synchronized method for the same object until the first...
What is a monitor?
What is a monitor? - A monitor works as a lock on the data item. When a thread holds the monitor for some data item, other....
Post your comment