I’m writing an application where I have many objects (data models) that are identified by a unique String ID that every such object possesses and these objects can refer to each other by their IDs.
So far so good but now I need to keep track of which object keeps a reference to another object and of course there are cases where an object references (or is referenced by) more than one other object and I was wondering what would be the best method to store these references? In a simple map data structure I could just map one object’s ID to another but as mentioned there are cases where an object can hold a ref to an arbitrary amount of other objects. Or I could map another map or an Array that hold more than one reference but I’d like to prevent iteration and maybe somebody knows a much better solution for this.
I guess it depends a lot in the particular use, but I think a Dictionary is the way to go, unless you need the order of the references, in which case I think an Array (or Vector) should work…
Whenever you have a dynamic arbitrary set of objects, I think you will necessarily need to iterate through them, whether its an array, object or dictionary.