Java Interface-Implementation Pair

Viewed 10448

Is there a preferred method or style of creating a default implementation for interface methods? Suppose I had a commonly used interface where in 90% of the cases the functionality I wanted was identical.

My first instinct is to create a concrete class with static methods. I would then delegate the functionality to the static methods when I want the default functionality.

Here is a simple example:

Interface

public interface StuffDoer{
    public abstract void doStuff();
}

Concrete Implementation of methods

public class ConcreteStuffDoer{
    public static void  doStuff(){
        dosomestuff...
    }
}

Concrete Implementation using default functionality

public class MyClass implements StuffDoer{
    public void  doStuff(){
        ConcreteSuffDoer.doStuff();        
    } 
}

Is there a better approach here?

EDIT

After seeing a few of the proposed solutions I think I should be more clear about my intent. Essentially I am trying to work around Java not allowing multiple inheritance. Also to be clear I am not trying to make a statement about whether or not Java should allow multiple inheritance. I am just looking for the best way to create a default method implementation for classes implementing an interface.

10 Answers
Related