I have 2 generic classes, a BaseComponent Class, and a BaseManager class.
They’re both abstract and are intended to be made concrete.
public abstract class BaseManager<T> where T : BaseComponent<?>
public abstract class BaseComponent<T> where T : BaseManager<?>
BaseManager has a list of BaseComponents, which is why i want to make it generic, so a PhysicsManager : BaseManager<PhysicsComponent> would have a list of PhysicsComponents.
I want (or rather, think i need) BaseComponent to be generic because i only ever want classes derived from BaseComponent to be ‘attached’ to their appropriate manager. Ideally i don’t want to have to write a constructor per derived component just so i can add it to a passed in concrete manager class. Ideally i want to have a constructor that takes the abstract BaseManager class.
How can i manage this kind of circular dependency?
It sounds like you might want to have two generic type parameters:
Yes, it’s smelly – but that’s the sort of thing I’ve done in Protocol Buffers.
So then you’d have: