So, for a little project I’m working on, I’ve been thinking about an item database architecture.
I have a base class, Item. I’ve merely included the code for the fields; the rest of the class is merely getters and setters, and a basic constructor.
// Item name & description.
private String name, desc;
// Cost per unit.
private long baseValuePerUnit;
// Size in meters cubed per unit.
private float sizePerUnitInM3;
That lays the groundwork for commodity-type items just fine - although it’ll be fun figuring out actual mathematically-correct values. A couple examples:
Item i1 = new Item("Mattress", "A mattress for sleeping on.", 200, 3.5f, false);
Item i2 = new Item("Iron Ore", "Unrefined iron-bearing ore.", 75, 0.001f, true);
There will be other kinds of items besides basic commodities, however, each with their own sort of information needed:
Fuel, requires information on energy density, etc.
Equipment, such as armor plating, shield generators, etc.
Each kind of equipment would require its own unique set of data
Armor plating: thermal rating, kinetic rating, etc.
Shield generator: thermal rating, kinetic rating, etc.
Now, I’m not a fan of inheritance. I would really like to avoid it.
To that end, I wanted to ask the folks of JGO, what’s your take?
My first idea was to put one of these in there:
private HashMap<String, Object> addedFields;
and then create a bunch of helper methods.
The other idea I had is to design a sort of super light-weight component system for the items, and then construct unique items via composition.
If you know of any design architectures that could work here, I’d love to hear. This is less of a question on “Hey, how do I do this exactly” and more of “Hey, what’s your thoughts and own experience on this sort of thing.” Links to working examples of open source code are also most welcome!