Assuming I have an interface and 3 or 4 classes that implement the interface. Now let's say I have another method but it is relevant only for one or two implementing classes.
So as I see it there are two approaches
- Declare the method in the interface, implement in all the classes. In classes that the method is not relevant - throw "not supported" exception.
- Declare the method only in the implementing classes where relevant but then you have to downcast the instance from interface type to the specific type in order to call the method. So would be your design here and why?
Aucun commentaire:
Enregistrer un commentaire