C
C#3y ago
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?
1 Reply
LukeJ
LukeJOP3y ago
Here's a picture if it helps illustrate what I mean. The light grey boxes are compound tasks encapsulating methods of both grey primitive tasks, and more light grey compound tasks. The right compound task is contained within the left one through Method 0. I should add as well, I don't know for certain they won't share anything beyond this. It's perfectly reasonable that, for example, I need to search for both types in the domain by a name field.
Want results from more Discord servers?
Add your server