Main Page | Class Hierarchy | Data Structures | File List | Data Fields | Globals

Subject Class Reference

#include <Subject.hpp>

Inheritance diagram for Subject:

Inheritance graph
[legend]

Detailed Description

Subject to observers.

This abstract class contains methods for the attachment and detachment of observers to itself. When a class is a subclass of the Subject class, subclasses of the Observer class can register and unregister themselves as observers for the Subject subclass. The Subject subclass can then call the notify method to send notice about special events to all the observing classes.

Internals
There exists only one notify method which contains a message code. This was considered superior to defining notification methods for all possible message types, because it can much more easily be extended by just defining new message codes.

The observers do not register for special events, instead, they are notified of all events and have to decide themselves if the triggered event is of interest to them or not.


Public Member Functions

 Subject ()
 Constructor.
virtual ~Subject ()
 Destructor.
virtual void attach (Observer *obs)
 Attach an observer.
virtual void detach (Observer *obs)
 Detach an observer.
virtual void notify (long msg, Item item=Item())
 Notify observers of an event.
virtual std::list< Observer * > get_observers ()
 Get observer list.

Protected Attributes

std::list< Observer * > observers
 A list of all registered observers.


Constructor & Destructor Documentation

Subject  ) 
 

Constructor.

~Subject  )  [virtual]
 

Destructor.


Member Function Documentation

void attach Observer obs  )  [virtual]
 

Attach an observer.

void detach Observer obs  )  [virtual]
 

Detach an observer.

std::list< Observer * > get_observers  )  [virtual]
 

Get observer list.

Returns:
Returns an std::list<Observer*> of all observers of a Subject

void notify long  msg,
Item  item = Item()
[virtual]
 

Notify observers of an event.

Usage example:

 Subject::notify(Message::new_node, Item(node));

Parameters:
msg The message code, this should be one of the codes defined in the Message class
item This contains the subject of the message, for example a node. See the Item class.


Field Documentation

std::list<Observer*> observers [protected]
 

A list of all registered observers.


Generated on Sun Nov 5 12:06:32 2006 for Graph by  doxygen 1.4.1