I have a situation similar to the following:
class EventHandler { ... };
class Event {void Accept(EventHandler&) { ... }};
class SpecialEventHandler : public EventHandler { ... };
class SpecialEvent : public Event {void Accept(SpecialEventHandler&) { ... }};
There are some events which are a subtype of Event
and some which are a subtype of SpecialEvent
. These events get added to a queue of Event
s and then I need to handle them with a SpecialEventHandler
.
The problem is handling the special events as the only the Accept
method that can be called is the one in Event
so only an EventHandler
can be passed in. I have a solution using a double visitor pattern but this is clunky and confusing.
- Is there a pattern for this kind of situation?
- Is there a better way to design it?