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

Observer Class Reference

#include <Observer.hpp>

Inheritance diagram for Observer:

Inheritance graph
[legend]

Detailed Description

Observer class.

This class has only one method: the update() method. It is called by the Subject subclasses to which the Observer subclass was attached. It contains a pointer to the subject, so that the subject which sent the update can be itentified. The message is a message code from the Message class. The message should always be checked for, because the update method will be called for all events in the Subject subclass. There is no guarantee that there will always be only the currently specified Messages.

An example implementation of the update method in a subclass of the Observer class could look like this:

 // Subject* graph1, Subject* graph2
 void update(Subject *sub, long msg, Item item)
 {
   if( sub == graph1 )
   {
     if( msg == Message::new_node )
     {
       // do something with item.node
     }
     else if( msg == Message::del_node )
     {
       // do something with item.node before it's deleted
     }
     else if( msg == Message:del_node_done )
     {
       // item has no valid members
     }
   }
   else if( sub == graph2 )
   {
     // see above
   }
 }

Internals
The idea to use only a single update function was considered to be superior to updates for specific events, because it can so easily be extended to new message types. If there is the need for a new message, it can be added to the Message class. If there is the need for a new message subject, it can be added to the Item class.


Public Member Functions

 Observer ()
 Empty Constructor.
virtual ~Observer ()
 Virtual destructor.
virtual void update (Subject *sub, long msg, Item item)=0
 Notification about an update.


Constructor & Destructor Documentation

Observer  )  [inline]
 

Empty Constructor.

virtual ~Observer  )  [inline, virtual]
 

Virtual destructor.


Member Function Documentation

virtual void update Subject sub,
long  msg,
Item  item
[pure virtual]
 

Notification about an update.

Implemented in Hierarchy, and View.


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