S
Stefano Sabatini
Hi all,
I'm facing this design problem.
I have a table which defines the behaviour of an Object in a given
state according to the type of event it is receiving.
So for each couple event,state I want I set in the table a different
handler.
My trivial implementation make use of defines (but I could have used
an enum as well).
So I have:
#define EVT_FOO 0
#define EVT_BAR 1
....
#define EVT_FOOBAR N
Then I define for each event a virtual GetType() which returns the
event type.
This is ugly and awkward, since everytime I add an event I have to
update the enum/list of defines, while I would like to be able to
automatically get a different integer for every derived class of
Event.
Mayeb I could get this result with some kind of run-time registration
mechanism.
I think this problem should be quite common, so I thought maybe
someone can suggest a better design than that which requires the
enum/defines list.
Regards.
I'm facing this design problem.
I have a table which defines the behaviour of an Object in a given
state according to the type of event it is receiving.
So for each couple event,state I want I set in the table a different
handler.
My trivial implementation make use of defines (but I could have used
an enum as well).
So I have:
#define EVT_FOO 0
#define EVT_BAR 1
....
#define EVT_FOOBAR N
Then I define for each event a virtual GetType() which returns the
event type.
This is ugly and awkward, since everytime I add an event I have to
update the enum/list of defines, while I would like to be able to
automatically get a different integer for every derived class of
Event.
Mayeb I could get this result with some kind of run-time registration
mechanism.
I think this problem should be quite common, so I thought maybe
someone can suggest a better design than that which requires the
enum/defines list.
Regards.