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.
|