Lecture 14





Lecture Topic:
Observer and Observable
Java has a model-view paradigm. In this
model, an observable object has to have the ability to maintain and update
a list of interested observers. Observers implement observer interface when
it wants to be informed if observable objects change.
(1). To maintain a list of observers, observers have to register
themselves by calling:
Observable.addObserver(this);
(2). The observable object will notify the observers by calling
Observable.notifyObservers();
(3). Observers must implement the Update() method in order to get updated.
An observable object can have one or more observers. After an observable
instance changes, an application calling the Observerable's notifyObservers
method causes all of its observers to be notified of the change by a call to
their update method.
Parent and Super Classes
- Parent is the superior container.
- Super is an ancestor class.
Example:
class a_frame extends Frame {
P p_pane = new P();
...;
}
class P extends Pane {
Parent.press(); // refer to frame container
Super.hide(); // refer to Pane base class
parent.hide(); // refer to frame container
}
Sample
Quiz
1 An observable class can be subclassed to represent an object that the
application wants to have observed.
a. TRUE
b. FALSE
2. Super class is the base class of derived classes?
a. TRUE.
b. FALSE.
3. Parent class can contain other classes as though they are its property?
a. TRUE.
b. FALSE.





Last Update: 1/4/97
Copyright © 1996,1997 - Douglas Lyon
Lyon@cse.bridgeport.edu