I have a tricky question on interface. Please try to give me a solution for it.
Scenario: I have written an interface with five methods. Also I have implemented more than 100 classes using this interface. Now, I need to add one more method to the interface. Consequently, I will need to define the same method in all classes. How can I avoid this???
Please reply...
Thanks, Akif
An interface can extend any number of interfaces but one interface cannot implement another interface, because if any interface is implemented then its methods must be defined and interface never has the definition of any method.
Right-click the name of the interface. On the shortcut menu, choose Add > Add Method. In the Add Method wizard dialog box, provide the information to create the method as described in the next section. Select OK to add the method.
An interface can extend other interfaces, just as a class subclass or extend another class. However, whereas a class can extend only one other class, an interface can extend any number of interfaces.
No, its an error If two interfaces contain a method with the same signature but different return types, then it is impossible to implement both the interface simultaneously.
Could you avoid adding a method to the interface by instead creating a new interface which inherits from that first interface and then only changing the classes you need that new method on? Hence, if foo didn't need the new method, leave it alone but if bar did, change it to the new interface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With