C#C
C#4y ago
2 replies
LukeJ

Collection of different classes

I have a situation where I need to store two different types together, and I'm not sure what's a good way to do it.

I am currently making an AI where one of it's defining characteristics is a hierarchy of tasks. These are either PrimitiveTask's, which contain a small chunk of behaviour, and CompoundTask's, which contain different methods to branch off to, which then contain a set of Primitive and/or Compound tasks.

Especially given the order these are processed in dictates the behaviour plan created, it means storing both task types in one collection. Making in interface to bind them by though, it's apparent they don't actually share any behaviour. They both get processed by a planner and are stored together in a domain, but that's about it. It's not really what an interface is for.

This leaves me wondering, how should I store them? I've heard attributes can be good for this sort of thing, but I'm not sure they fit here (I've not used them enough to really say). I could store them separately and have a third collection stating the order to take from the two separate collections, but that feels pretty hacky. Maybe this is a sensible scenario to have an empty interface for marking classes with. Thoughts?
unknown.png
Was this page helpful?