Observer Pattern - Events containing different data

C

Christopher

The observer pattern itself is easy enough. I've implemented it using
a Event that contains data for any Event type I forsee my application
using. My problem is I don't want one and only one general purpose
type of Event. I want to write my design in such a way that more Event
Types can be created and used down the road as needed. How can you
design the Events in such a way that more can be handled later by the
same Observer and Subject classes when they don't know what your
Events look like right now?
 
V

Victor Bazarov

Christopher said:
The observer pattern itself is easy enough. I've implemented it using
a Event that contains data for any Event type I forsee my application
using. My problem is I don't want one and only one general purpose
type of Event. I want to write my design in such a way that more Event
Types can be created and used down the road as needed. How can you
design the Events in such a way that more can be handled later by the
same Observer and Subject classes when they don't know what your
Events look like right now?

I am not sure this is a C++ question. Try 'comp.object' as well.

I would probably try to design a polymorphic pair Observer/Event. You
cannot make the same observer observe any type of event, but you can
make more [different] observers to observe the events they know about.
Also, in such case you can make Events aware of the Observers that can
observe them...

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top