Interface Subject<T,O extends Observer<T>>
- Type Parameters:
T
- the generic type of the observable object whose state is being observedO
- the generic type of the observer that is observing the subject
- All Known Implementing Classes:
AbstractSubject
,ChatRoom
public interface Subject<T,O extends Observer<T>>
The interface
Subject
represents the "subject" in the Observer design pattern The subject
is the object whose state changes are being observed by one or more observers When the state of
the subject changes, the observers are notified of the change-
Method Summary
Modifier and TypeMethodDescriptiondefault void
Adds the given observer to the list of observersdefault void
addAll
(Collection<O> observers) Adds the given observers to the list of observersGets the observable object, which is the object being observed for state changesGets the list of observers that wish to be notified of changes to the observable objectdefault void
Removes the given observer from the list of observersdefault void
removeAll
(Collection<O> observers) Removes the given observers from the list of observersvoid
setObservable
(T observable) Sets the observable object, which is the object being observed for state changesdefault void
Notifies all observers of a change in the state of the observable object Each observer'supdate
method is called with the current state of the observable
-
Method Details
-
add
Adds the given observer to the list of observers- Parameters:
observer
- the observer to be added
-
addAll
Adds the given observers to the list of observers- Parameters:
observers
- the observers to be added
-
getObservable
T getObservable()Gets the observable object, which is the object being observed for state changes- Returns:
- the observable object
-
setObservable
Sets the observable object, which is the object being observed for state changes- Parameters:
observable
- the new observable object
-
getObservers
Gets the list of observers that wish to be notified of changes to the observable object- Returns:
- the list of observers
-
remove
Removes the given observer from the list of observers- Parameters:
observer
- the observer to be removed
-
removeAll
Removes the given observers from the list of observers- Parameters:
observers
- the observers to be removed
-
updateObservers
default void updateObservers()Notifies all observers of a change in the state of the observable object Each observer'supdate
method is called with the current state of the observable
-