I have this class EventGenerator
that can generate objects of any subclass of an interface Event
. I would like to allow objects to implement a method that receives a specific subclass T
of Event
that will be called when the generator emits a new event of that type.
I would like to follow the Open-Closed principle as much as possible, since subclasses of Event
may be created in the future. I was thinking about an interface EventSubscriber<T extends Event>
with a method receiveEvent(T)
, but how can I add and store the subscriber in the generator object?
Aucun commentaire:
Enregistrer un commentaire