I have multiple 'Event' Types (EventB, EventC,EventD...), all extending a single event type EventA. There are multiple actions i would like to implement and run on each of the event types. I would like for each actions to be run on both the super and the extending class.
This can be implemented with regular inheritance and virtual methods, but the reason i am interested in visitor pattern for this case is that i would like to be able to add a new Action for each of the event types with releative ease. Visitor pattern will allow me to add a new (and single) ActionHandler class with visit(EventA), visit(EventB), ...
methods and not need to add a new doSomeAction() method in each of the classes.
I would like the visit(EventX)
method to first call visit(EventA)
before running its own code (EventA is the super class of all events)
Are there good solution for this problem other than start each visit(EventX)
function in all of the EventHandlers classes with visit((EventA)event)
?
Aucun commentaire:
Enregistrer un commentaire