I have the following code:
public class A {
private int id;
private String name = null;
private static int counter = 0;
private static Stack<A> pool = new Stack<>();
private A (){
A.counter += 1;
setId();
}
private void setId(){
id = A.counter;
}
public void setName(String name) {
this.name = name;
}
public static A getInstance() {
A element;
try {
element = pool.pop();
} catch (EmptyStackException e) {
element = new A();
}
return element;
}
public static void returnInstance(A element) {
pool.push(element);
}
}
How can I externalize the getInstance(), returnInstance() and the private static Stack pool to an abstract class?