I'm making a video game and and I would like to know if my OO Inventory System has any flaws or oversightes.

Here is the the item system anything that can be stored in an inventory system is an item. The composition of the item class is a shield,a weapon, an engine, and a ship.


  • Ship ship
  • Engine engine
  • Weapon weapon
  • Shield shield

The ships class contains information on its stats(speed,armor,name,description) an is composed of weapons,a shield, an inventory, and one engine.


  1. Engine engine
  2. Weapon weapon
  3. String name
  4. string shipDescription
  5. float speed
  6. float armor
  7. Shield shield

The Weapons class contains info on stats of the weapon it is Weapon:

  • float rateOfFire
  • int maxAmmoCapacity
  • int currentAmmoAmount
  • int rating
  • float damage
  • string name
  • string description

The shield class Shield:

  • int rating
  • int shieldType
  • float damageAbsorpotionRate
  • float regenerationRate
  • string name
  • string description
  • int rating

The Inventory class contains an array to limit the amount of Items it can store and two functions for removing and adding items into/out of the inventory list.


  • Items[] items
  • AddItem(Item item)
  • RemoveItem(Item item
  • 2
    You describe a class hierarchy, but then describe no code that has anything to do with the subclasses. Is it relevant here? Commented Jun 8, 2016 at 10:03
  • It could be, I'll add information about the subclasses in an edit. Commented Jun 8, 2016 at 10:11
  • 3
    Standard problem you'll encounter when using inheritance rather than composition: how will you handle a shield that can cause damage (ie is also a weapon) or a weapon that can create protection (ie is also a shield)? Don't use inheritance.
    – David Arno
    Commented Jun 8, 2016 at 10:11
  • 2
    I think that a main problem you will face using a polymorphic inventory is that your classes will be in a generic type and you will have to downcast them to use their specific parts. So that means downcasting OR subclassing with no specific part. I would avoid both. Composing inside item would be better in that regard
    – Diane M
    Commented Jun 8, 2016 at 10:20
  • 2
    @user2883202, a standard way to use composition is to have Item contain a list of IFeature. Each feature, such as engine, weapon etc is then implements Ifeature as well as IEngine, IWeapon etc respectively. If you then later decide you want a shield with weapon abilities, you create a feature class that implements both IShield and IWeapon. Then, for example, to test whether an item behaves as an engine, you check if an IEngine exists in its features.
    – David Arno
    Commented Jun 8, 2016 at 10:51

1 Answer 1


That's a very confusing specification. "The composition of the item class is a shield,a weapon, an engine, and a ship" : what does it means? An item is composed by a shield, a weapon, an engine and a ship or an item can be a shield, a weapon, an engine and a ship? A ship is an item (that's counterintuitive but it could be, explain how)? Moreover the most difficult and error pronig part, that is how this objects interact together, is omitted: Can a ship without a weapon exist? A ship can have only one weapon? When you will add an Item to the Invetory will you have a pointer to an inventory instance? Item is an interface or a superclass? Because according to what you have written it could be both. You write "The Inventory class contains an array to limit the amount of Items" but an array can't limit any amount. And ... what if i need to retrieve an Item from an Inventory? Are you sure you don't need a .get() method? You want to get items with a fifo policy or you have other requirements? In practice those analisys lead to failed projects. Writing a specification or analize a problem is a very complex task and should be done very carefully considering all possible scenarios. It's impossible to state if your inventory system has
flaws or oversightes because your inventory system's definition is poor/bad.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.