I have to listen to an event from an event emitting class ; for Example click
. Current i have class which handles it the events from the event emitting class like this.
someclass.clickedOnItem1()
someclass.clickedOnItem2()
where someclass is
class Someclass {
//functions clickedOnItem1() and clickedOnItem2()
}
note that Someclass does not implement an interface. My problem is that i want only certain subclasses of Someclass to have this behavior and have the capacity to override the behavior but also have some default behavior in class Someclass. The default behaviour of Someclass depends on specific behavior which is only available in certain subclasses. I was considering composition where each subclass can provide a custom implemntation of an interface which handles click events. I am currently looking for advice on the best possible design pattern which can address this issue.
Aucun commentaire:
Enregistrer un commentaire