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

dk.rode.thesis.observer
Class BirthdayRegistry.RegistryObserver<A>

java.lang.Object
  extended by dk.rode.thesis.observer.BirthdayRegistry.RegistryObserver<A>
Type Parameters:
A - The type of aspect used in the notification. The actual value is ignored.
All Implemented Interfaces:
SequenceObserver<A>
Enclosing class:
BirthdayRegistry

private final class BirthdayRegistry.RegistryObserver<A>
extends Object
implements SequenceObserver<A>

A registry observer forwards call to the enclosing registry. hashCode and equals are overridden to ensure that the same registry is not added twice to a given observable sequence.

Implementation notes:
This is an application of the Adapter pattern, in effect adapting a BirthdayRegistry to the SequenceObserver interface.

Author:
Gunni Rode / rode.dk

Constructor Summary
private BirthdayRegistry.RegistryObserver()
          No-arg constructor.
 
Method Summary
 boolean equals(Object object)
          Returns true if object is a registry observer wrapping the same registry as this observer, false if not.
 int hashCode()
          Returns the hash code of this observer.
private  BirthdayRegistry registry()
          Returns the enclosing birthday registry for this observer.
 void sequenceEvent(Sequence<?> sequence, A aspect)
          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, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BirthdayRegistry.RegistryObserver

private BirthdayRegistry.RegistryObserver()
No-arg constructor.

Method Detail

equals

public boolean equals(Object object)
Returns true if object is a registry observer wrapping the same registry as this observer, false if not.

Overrides:
equals in class Object
Parameters:
object - The object to test; can be null.
Returns:
True if equal, false if not.

hashCode

public int hashCode()
Returns the hash code of this observer.

Overrides:
hashCode in class Object
Returns:
The hash code.

registry

private final BirthdayRegistry registry()
Returns the enclosing birthday registry for this observer.

Returns:
The registry; never null.

sequenceEvent

public void sequenceEvent(Sequence<?> sequence,
                          A aspect)
Description copied from interface: SequenceObserver
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.

Specified by:
sequenceEvent in interface SequenceObserver<A>
Parameters:
sequence - This sequence; cannot be null.
aspect - 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.