Java interface


Web tier: servlets, JSP, Web frameworks: Java interface

  1. Java interface (1 messages)

    Can anyone please advise on Below question, I was recently asked this question on a Java Interview 

    Suppose you have an interface say XYZ, which has been implemented by dozens of classes. Now you need to add another method in that interface XYZ. What would be your approach to make that change in minimal way to solve the problem of overriding that method in all implementing classes?

    Threaded Messages (1)

  2. Java interface[ Go to top ]

    I can see two posibilities:

    1. creating sub-interface that extends XYZ interface and declare another method in there. Drawback is that you can't use this method is you have instance of parent interface. 

    2. Add another method into XYZ interface, create abstract class that implements this method (even  empty method is suitable) and change implementors of interface to extend this abstract class.

    Which one to choose depends on concrete requirements and existing usage of the interface.