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

dk.rode.thesis.observer
Class PrintSequenceObserver

java.lang.Object
  extended by dk.rode.thesis.observer.PrintSequenceObserver
All Implemented Interfaces:
SequenceObserver<Sequence.State>

@Participant(value="ConcreteObserver")
public class PrintSequenceObserver
extends Object
implements SequenceObserver<Sequence.State>

A print sequence observer prints the state of any observable sequence it is observing.

Implementation notes:
The sequenceEvent(Sequence, Sequence.State) method is also annotated with the Executor annotation and instances of this class can thus also be observers for AnnotatedObserversSequence sub-classes or used directly by the ObserverManager class.

Author:
Gunni Rode / rode.dk

Field Summary
private  StringablePolicy<Sequence<?>> policy
          The policy to use to print the observable sequence.
 
Constructor Summary
PrintSequenceObserver()
          Constructor.
PrintSequenceObserver(StringablePolicy<Sequence<?>> policy)
          Constructor.
 
Method Summary
 void sequenceEvent(Sequence<?> sequence, Sequence.State state)
          Notification method that is invoked when the sequence supplied as sequence has changed its state to state.
 String toString()
          Returns the string representation of this observer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

policy

private final StringablePolicy<Sequence<?>> policy
The policy to use to print the observable sequence.

Can be null, i.e. default policy.

Constructor Detail

PrintSequenceObserver

public PrintSequenceObserver()
Constructor.

The default policy for the observable sequence is used.


PrintSequenceObserver

public PrintSequenceObserver(StringablePolicy<Sequence<?>> policy)
Constructor.

Parameters:
policy - The policy to use; can be null, i.e. default policy.
Throws:
NullPointerException - If out is null.
Method Detail

sequenceEvent

@Executor
public void sequenceEvent(Sequence<?> sequence,
                                   Sequence.State state)
Notification method that is invoked when the sequence supplied as sequence has changed its state to state.

The type of sequence is not defined; it cannot be assumed observable, or even of the type this observer was attached to; it might be adapted, decorated, composite, or proxied.

This method is annotated with the Executor annotation and can thus also be used to notify instances of this class using any implementation of AnnotatedObserversSequence as well.

Specified by:
sequenceEvent in interface SequenceObserver<Sequence.State>
Parameters:
sequence - This sequence; cannot be null.
state - The current (new) aspect; cannot be null.

toString

public String toString()
Returns the string representation of this observer.

Overrides:
toString in class Object
Returns:
The string representation; never null.

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.