This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Your ideas are basically correct. If the objects are all of the same type, then instead of using an array, I might use multiple Maps (like java.util.HashMap). Looking things up in a Map is both simpler and faster than searching linearly through an array. You could use one map for each variable, and use the value of the variable as the key for an object.
If you want to do this for many different kinds of objects, then the best thing to do (conceptually) would be to put the objects into a database, with a table like
Then you can find the objects of interest using a database query. There are lots of different databases to choose from, including library-based in-memory ones and free software ones.
And yes it does help very much. Next on the learning curve is hashmaps. The objects all have the same base class so I may adjust things to make it easier. Its just a matter of working out exactly what has to happen.
I was intending to use a database for something else, but after re-reading your post a few times you gave me an idea. Can multiple maps be used to store a reference to code that will be chosen from at run-time? Like maybe handed to a new thread while the main one is halted to wait for the return? Even if the reference was just to a file location containing the code. With something like that I could avoid using (learning about) a database entirely and store everything in a seperate file.
Then again the size could run to a few hundred entries, is that an acceptable overhead for the map?