How are Observer and Observable used?- All the objects which are the instances of the sub class Observable, maintains a list of observers.
- At the time of updating an Observable object, it invokes the update() method of each of its observers for notifying the observers which has changed its state.
- The objects implement the Observer interface which observes Observable objects.
- 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. - For example, third-party software cannot be made Observable without changing an existing class hierarchy.
- 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.
|