I have a superclass called BaseClass
which has a table called children
in which it should have subclasses of BaseClass
, How would I make a table like that and make a method that returns that table? Also how should I be storing that table in the other classes that are requesting it?
Here is my current code:
public class BaseClass<T> {
// // // Private Variables // // //
private int ParentChildID;
private int NextChildID = 0;
private BaseClass Parent;
private BaseClass[] children;
// // // Public Variables // // //
public String Name = "BaseClass";
public String ClassName = "BaseClass";
// // // Private Methods // // //
private void destroyChild(int ChildID) {
children[ChildID] = null;
}
private void addChild(BaseClass Child) {
children[NextChildID] = Child;
Child.Parent = this;
NextChildID++;
}
// // // Public Methods // // //
public void destroy() {
if (Parent != null) {
Parent.destroyChild(ParentChildID);
}
}
public void clearAllChildren() {
for (int i = 0; i < children.length; i++) {
children[i] = null;
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public BaseClass setParent(BaseClass Parent) {
Parent.addChild(this);
destroy();
this.Parent = Parent;
return this;
}
public BaseClass[] getChildren() {
return children;
}
}
>` where `S` is a subclass hen use `Listchildren = /*init to ArrayList or LinkedList*/;`.