I have a base class that captures some functionality common to two classes. In other words, I can create one base class and make these two classes subclasses of that base cl
I don't know if you need an example but I gave it a try. Without knowing any of your details this example is very vague. I am also here to learn so let us know what you end up implementing.
The Base class:
public abstract class BaseClass {
public void someMethod() {
System.out.println("base class hello: " + this);
}
public abstract void someOtherMethod(String value);
}
One of the subclasses:
public class SubClassOne extends BaseClass {
private static SubClassOne instance;
private SubClassOne() {}
public static SubClassOne getInstance() {
if (instance == null) {
instance = new SubClassOne();
}
return instance;
}
public void someOtherMethod(String value) {
someMethod();
System.out.println("sub class hello: " + value + " " + this);
}
public static void main(String[] args) {
SubClassOne one = SubClassOne.getInstance();
SubClassOne two = SubClassOne.getInstance();
SubClassOne three = SubClassOne.getInstance();
SubClassOne four = SubClassOne.getInstance();
one.someOtherMethod("one");
two.someOtherMethod("two");
three.someOtherMethod("three");
four.someOtherMethod("four");
}
}