Sorry I really didn't know how to title the question, here's the problem...
I have an interface and multiple classes that implement the interface. The implementation of some of the methods in the interface are exactly the same in every implementing class. I feel like there should be a way to simplify this so I don't have to write the same code every time. Example:
public interface Foo {
String getName();
}
public class FooImpl1 implements Foo {
private String name = "foo name1";
public String getName(){
return name;
}
}
public class FooImpl2 implements Foo {
private String name = "foo name2";
public String getName(){
return name;
}
}
So to break down..
is there a way to put the code for getName in one place and each class has it's own name variable?
is there a way to make getName static so I don't have to create a new instance
Have better ideas?