Even trying to come up with a clean title for this is a challenge.
The basic idea is to have two superclasses defined: one for "child" items with a member that references its "parent", the other for the "parent" lists that contain child objects. The links from child->parent and parent->child are symmetrical. Each of the parent/child superclasses have subclasses that define and implement additional functionality. There is always a parallel subclass such that child<A>
pairs with parent<A>
. That is, parent<A>
will only contain child<A>
references, and child<A>
will only refer to a parent<A>
- there is no "crossing over" between the subtypes.
How can I represent this? I've been stuck on this for days and the more creative I am with multi-level nested generic types the worse it gets. This is what I'd like to do:
abstract class ChildBase<T extends ChildBase<T>> {
ParentBase<T> parent;
}
abstract class ParentBase<T extends ChildBase<T>> {
LinkedList<T> childList;
}
class ChildSub extends ChildBase<ChildSub> {
// ... class specific stuff
}
class ParentSub extends ParentBase<ChildSub> {
// ... class specific stuff
}
This is a mess. I suspect that there is a much simpler, straightforward way of doing this and it's probably in a totally different direction.