|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
O
- The type of observers associated with this observable.@Participant(value="Subject") public interface Observable<O>
An observable object is an object that has a collection of associated observers to be notified in case the object changes its internal state, or aspect.
This interface only supplies the logic for
adding
, removing
, and fetching
associated
observers, but no notification method to notify the
observers.
Instead, the type of observers is supplied as the type
parameter O
and implementing classes must supply
the notification mechanism. This allows for greater flexibility,
for example asynchronous notification, as well as the use of
different methods.
Implementation notes:
This is essentially an application of the
Composite pattern.
It is not allowed to implement the same generic interface more
than once by a given type because erasure will cause the signatures
to conflict. Hence, an observable type should instead use a
broader type of O
to allow different unique observer
types. Internally, composition could then be used via stand-alone
Observable
implementations, such as the
ObserverManager
class, each handling a specific type
of observers.
AspectObservable
Method Summary | |
---|---|
boolean |
addObserver(O observer)
Adds the observer supplied as observer to this observable,
if not already. |
Collection<O> |
getObservers()
Returns the observers currently associated with this observable sequence. |
boolean |
removeObserver(Object observer)
Removes the observer supplied as observer from this
observable, if already added. |
Method Detail |
---|
boolean addObserver(@Participant(value="ConcreteObserver") O observer)
observer
to this observable,
if not already.
observer
- The observer to add; cannot be null.
observer
was added, false if not.
NullPointerException
- If observer
is null.
IllegalArgumentException
- If observer
is not
a valid observer to add to this observable (optional).removeObserver(Object)
Collection<O> getObservers()
No specific order is maintained.
Modifying the returned collection will not affect this observable.
boolean removeObserver(Object observer)
observer
from this
observable, if already added. Trying to remove an observer that is not associated with this observable has no effect.
observer
- The observer to remove; cannot be null.
observer
was removed, false if not.
NullPointerException
- If observer
is null.addObserver(Object)
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |