Abstract class get parameter from implementing subclass?
- by soren.qvist
I'm wondering if there is way to do this without breaking encapsulation, I want the abstract class to rely on parameters defined in the implementing subclass. Like so:
public abstract class Parent {
private int size;
private List<String> someList;
public Parent() {
size = getSize();
someList = new ArrayList<String>(size);
}
public abstract int getSize();
}
public class Child extends Parent {
@Override
public int getSize() {
return 5;
}
}
Is this ugly? Is there a better way? And perhaps more importantly, is this even a good idea?