Partial implementation of an interface

You can do this by creating an abstract class that implements the interface. Any sub-class of this abstract class will be required to implement any interface methods that were not yet defined.

public abstract class AbstractInterface implements interface1 {
    @Override
    public String getVar1() {

    }

    @Override
    public void method1() {

    }
}
public class Implementation extends AbstractInterface {
    @Override
    public void method2() {

    }
}

See: Java tutorial on abstract classes.


You can create an abstract class which does not implement method2()

public abstract class AbstractImplementation implements interface1 {
    public String getVar1() { 
      // implementation ..
    }

    public void  method1() {
      // implementation ..
    }

    // skip method2
}

Then create multiple implementations:

public class Implementation1 extends AbstractImplementation {
    public void method2() {
      // implementation 1
    }
} 

public class Implementation2 extends AbstractImplementation {
    public void method2() {
      // implementation 2
    }
}

...

Tags:

Java