Class Observable<S extends Observable<S>>
java.lang.Object
nz.ac.vuw.ecs.swen225.gp22.domain.Observable<S>
- Direct Known Subclasses:
Entity
A class can extend this so an instance of it
can be observed by Observer objects.
- Author:
- Abdul
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addObserver
(Observer<S> observer) Adds an Observer to the list of observers.void
removeObserver
(Observer<S> observer) Removes an Observer from the list of observers.void
Calls the update() method for each observer attached to this object.
-
Constructor Details
-
Observable
public Observable()
-
-
Method Details
-
addObserver
Adds an Observer to the list of observers.- Parameters:
observer
- Observer to be added.
-
removeObserver
Removes an Observer from the list of observers.- Parameters:
observer
- Observer to be removed.
-
updateObservers
public void updateObservers()Calls the update() method for each observer attached to this object. This method suppresses the unchecked cast because type S is always a subtype of Observable with the generic type also being S, and the value of 'this' will also be a subtype of Observable with the generic type also being S, so the cast is safe.
-