its the functions thats only purpose is to just call other functions that is a little weird to me, but maybe this is totally acceptable, im not sure. Im basically just re defining the same functions in a different class that calls those same functions. |
I think the idea is to
hide the implementation details (and some possible complexity) in the
Inventory class. Maybe, at this time, the methods of your
Inventory class are just thin wrappers around
std::vector or
std::map, but the
users of your
Inventory class don't have to know or care! They just use the public
Inventory interface, unknowingly how it is implemented internally. Maybe, at a later time, you'll decide that the
Inventory class should maintain the items in a different way, e.g. you may want to use a
std::multimap from now on. This then would be a change
internal to the
Inventory class. Users of the existing
Inventory interface don't need to be updated!
If, instead, all entities that need to maintain an inventory would be using
std::vector or
std::map directly, then changing the way how an inventory is implemented becomes
much harder, because it would require changes in a lot of different places...
Also, you may want to add some "helper" methods to operate on the inventory. For example,
removeAllBrokenItems()
or whatever. The
Inventory
class would be the perfect place to implement such "helper" methods at a single sensible place.
Without a dedicated
Inventory
class, however, such methods would have to be in the class that uses the inventory (e.g. in the
Character class), which is
not a good separation of duties. Even worse, if the "helper" method is required by more than one class that works with an inventory, then you'd have to create multiple redundant copies of the "helper" method – one in each class that works with the inventory. But, redundant code always is a bad idea! So, I think it will be much better to encapsulate all inventory-related methods in its own dedicated class.
In general, it is always good to break down your program into small self-contained units which communicated via well-defined interfaces. The "internals" of such units may change over time, but the interface should remain stable, or at least only be "extended" in backwards-compatible ways. This way, you can easily change/improve your implementation
without having to worry that it will break something...