View Single Post
  #6 (permalink)  
Old 10-24-2007, 03:43 PM
kkelly's Avatar   
kkelly kkelly is offline
Learning Programmer
 
Join Date: Sep 2007
Posts: 50
Rep Power: 5
kkelly is on a distinguished road
Default

In my last assignment I encountered something like your discussing.

I ended up creating a virtual base class that contained only public event functions; Basically, an interface class. Just remember to use a virtual destructor. If a class needed to handle those events, it would have to inherit the interface. For the class that called the event functions, I created a pointer (of the Interface type) and assigned it to an event handler object (instance of a derived class of the Interface Class). Then I called (raised) the event through the pointer. Like:
Code:
InterfaceClass * ptrInterfaceClass = new EventHandlingClass;
ptrInterfaceClass->SomeEvent();
You can assign an InterfaceClass * to any class that inherits the Interface class. You can used a linked list of Interface class pointers if you need add eventhandlers during run-time.
I should note that I never added asynchronous execution to the assignment, and I'm not sure how that would effect the design I used.
I hope that helps.
Reply With Quote