How are Observer and Observable used in Java?

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.
What is synchronization and why is it important in Java?
Synchronization is the process of allowing threads to execute one after another...
Difference between preemptive scheduling and time slicing in Java
Preemptive scheduling enables the highest priority task execution until waiting or dead states entered...
What is a task's priority and how is it used in scheduling?
A task’s priority is an integer value. This value is used to identify the relative order of execution with respect to other tasks...
Post your comment