Evaluating Software Design Patterns
— the "Gang of Four" patterns implemented in Java 6

dk.rode.thesis.observer
Interface AspectObservable<O,A>

Type Parameters:
O - The type of observers associated with this observable.
A - The type of aspect associated with this observable.
All Superinterfaces:
Observable<O>
All Known Subinterfaces:
AspectObservableSequence<O,A,E>
All Known Implementing Classes:
DateSequence, SequenceObserversSequence, SequenceObserversSequenceDecorator

@Participant(value="Subject")
public interface AspectObservable<O,A>
extends Observable<O>

An aspect 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, and where the observers can subscribe certain aspects only.

This interface only supplies the logic for adding, removing, and fetching associated observers based on specific aspects, but no notification method to notify the observers. Using the get, add, and remove methods from ObservableSequence gets, subscribes, or removes regardless of aspect value (all possible aspect values).

Author:
Gunni Rode / rode.dk
See Also:
Observable

Method Summary
 boolean addObserver(O observer, A aspect)
          Adds the observer supplied as observer to this observable for the aspect supplied as aspect, if not already.
 Set<A> getAspects(O observer)
          Returns a read-only set of the aspects the observer supplied as observer subscribes to in this observable, if any.
 Collection<O> getObservers(A aspect)
          Returns the observers subscribed to the aspect supplied as aspect in this observable.
 boolean removeObserver(Object observer, A aspect)
          Removes the observer supplied as observer from this observable with regards to the aspect supplied as aspect, if already added to it.
 
Methods inherited from interface dk.rode.thesis.observer.Observable
addObserver, getObservers, removeObserver
 

Method Detail

addObserver

boolean addObserver(@Participant(value="ConcreteObserver")
                    O observer,
                    A aspect)
Adds the observer supplied as observer to this observable for the aspect supplied as aspect, if not already.

If aspect is null, observer will be subscribed to all possible aspect values.

Parameters:
observer - The observer to add; cannot be null.
aspect - The aspect to subscribe to; null means all.
Returns:
True if observer was added, false if not.
Throws:
NullPointerException - If observer is null.
IllegalArgumentException - If observer is not a valid observer to add to this observable (optional).
See Also:
removeObserver(Object, Object)

getAspects

Set<A> getAspects(O observer)
Returns a read-only set of the aspects the observer supplied as observer subscribes to in this observable, if any.

Parameters:
observer - The observer; cannot be null.
Returns:
A read-only list containing the aspect subscriptions; never null, but can be null.
Throws:
NullPointerException - If observer is null.

getObservers

Collection<O> getObservers(A aspect)
Returns the observers subscribed to the aspect supplied as aspect in this observable.

Parameters:
aspect - The aspect; null means all.
Returns:
The observers subscribing to the aspect supplied as aspect; never null, but can be empty.

removeObserver

boolean removeObserver(Object observer,
                       A aspect)
Removes the observer supplied as observer from this observable with regards to the aspect supplied as aspect, if already added to it.

Trying to remove an observer that is not associated with this observable or to an unsubscribed aspect has no effect.

Parameters:
observer - The observer to remove for aspect; cannot be null.
aspect - The aspect in question; null means all.
Returns:
True if observer was removed from the subscription to aspect (or all if null), false if not.
Throws:
NullPointerException - If observer is null.
See Also:
addObserver(Object, Object)

Gunni Rode / rode.dk

Feel free to use and/or modify the Java 6 source code developed for this thesis AT YOUR OWN RISK, but note that the source code comes WITHOUT ANY — and I do mean WITHOUT ANY — form of warranty WHAT SO EVER!

The original thesis and source code are available at rode.dk/thesis.