Hi,
I'm currently toying with an Inventory system for one of my project and I'm not sure on what the best approach is to avoid future hurdles.
The way it works is that it contains a series of 'components' each with their own ID, which are different types (there are 6 types of components, and any given component is one, and only one type at any given time).
Initially, I had created 6 Hashmaps (ordered by an integer, thus the component ID). This allowed me to quickly find all necessary information for a component's specifications when looking up the appropriate INT in the appropriate MAP.
As the project progressed, I ended up having a few generic methods in the code that could do with a more fluid approach (for example, creating a button that refers to 'any component' as it would effectively have the same behavior, such as when buying or selling that component).
I've been thinking up two solutions:
1 - Merge all of the inventories together and differentiate each component's type by adding a field named along the lines of 'component type'.
2 - Create a 'macro' hashmap that contains all of the submaps.
For example
macroMap[0] = componentType1Inventory
macroMap[1] = componentType2Inventory
macroMap[2] = componentType3Inventory
...
#1 seems like the cleanest methods, but #2 feels a lot more organic for what I'm trying to achieve (and prevents using unnecessary getters). I feel I'd get more mileage out of the 2nd approach because it prevents me from having to 'peek inside' any object to figure out if it should be considered or not (if it's in that sub-map, it is de facto meant to be in that list).
Any pointers on how I should approach this?