org.perfectjpattern.core.behavioral.observer
Class Subject<E>

java.lang.Object
  extended by org.perfectjpattern.core.behavioral.observer.Subject<E>
Type Parameters:
E - Type of event data this ISubject notifies with.
All Implemented Interfaces:
ISubject<E>
Direct Known Subclasses:
AsynchronousSubject, ParameterlessSubject

public class Subject<E>
extends Object
implements ISubject<E>

Base core implementation of ISubject interface.

Version:
$Revision: 1.0 $ $Date: Jun 18, 2007 9:06:39 PM $
Author:
Giovanni Azua
See Also:
ISubject
 

Field Summary
protected static IObserver[] EMPTY_ARRAY
          Reusable empty array of IObserver so it does not need to be recreated each time there is a call to notifyObservers
 
Constructor Summary
Subject()
           
 
Method Summary
 void attach(IObserver<E>... anObservers)
          Attaches a variable list of IObserver instances to the ISubject instance.
 void clear()
          Detaches all registered IObserver instances from this ISubject
 void detach(IObserver<E>... anObservers)
          Detaches a variable list of IObserver instances from the ISubject instance.
protected  Collection<IObserver<E>> getObservers()
          Returns the Observer instances
 void notifyObservers(E anEventData)
          Notifies the attached IObserver instances that a change has occurred.
 int size()
          Returns the number of attached IObserver instances
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ARRAY

protected static final IObserver[] EMPTY_ARRAY
Reusable empty array of IObserver so it does not need to be recreated each time there is a call to notifyObservers

Constructor Detail

Subject

public Subject()
Method Detail

attach

public void attach(IObserver<E>... anObservers)
Attaches a variable list of IObserver instances to the ISubject instance.

Specified by:
attach in interface ISubject<E>
Parameters:
anObservers - IObserver instances to be attached.

clear

public void clear()
Detaches all registered IObserver instances from this ISubject

Specified by:
clear in interface ISubject<E>

detach

public void detach(IObserver<E>... anObservers)
Detaches a variable list of IObserver instances from the ISubject instance.

Specified by:
detach in interface ISubject<E>
Parameters:
anObservers - IObserver instances to be detached.

notifyObservers

public void notifyObservers(E anEventData)
Notifies the attached IObserver instances that a change has occurred. It is compulsory to provide a non null parameter anEventData. For situations where passing information is not required use instead NullEventData singleton instance.

Specified by:
notifyObservers in interface ISubject<E>
Parameters:
anEventData - Event data pushed to IObserver instances.

size

public int size()
Returns the number of attached IObserver instances

Specified by:
size in interface ISubject<E>
Returns:
Number of attached IObserver instances.

getObservers

protected Collection<IObserver<E>> getObservers()
Returns the Observer instances

Returns:
the Observer instances


Copyright © 2007-2009. All Rights Reserved.