I have a generic class for all the managers that are in my framework. (Managers for entites, game alarms, physics, and particles for example).
Essentially they all do the same thing. They have a collection of things, they need to update those things, and they need to render those things (Well, not all managers need to render..but anyway). So I’ve got a generic base class that does exactly that. I define what ‘things’ it stores.
public class GenericManager<T> where T : Updatable
And objects in my game like entities/particles/etc inherit Updatable and away we go.
public class EntityManager : GenericManager<Entity>
and ofcourse, Entity is
public class Entity: Updatable
Now I am wondering how I would put all these managers into a list of managers. I need a way to store them all, iterate over them, and update them in yet another manager (I suppose).
PS This may not be an ideal way to handle what I am doing but this is really just a learning exerciser for me to get more comfortable with using generics.
you could do with just a simple empty manager interface to create the list and intersections based on the OfType extension method, like this