Heya all,

Right now, i'm working on a small, text-based game, but i'm a bit confused about how to get my coupeling right.

at the moment, i have 5 classes: an Item class, an inventory, a player, a room and a 'game' class that loads the game.

The game class has 1 player and a few rooms, the player and every room have an inventory and an inventory stores items.
when the game loads, the game class adds multipl items to the rooms and player, but i'm wondering where i should define my items.
If i create the items in my game class, would the coupeling get loose since an Item passes through a lot of other classes, or should i pass the item's parameters along to inventory class, through the player/room classes?


Where you create them and where you store them are two different things. It may be best for the Game class to have responsibility for creating everything, including Items, but then immediately adding them to the appropriate Inventory.

Coupling is always a bit of a question in respect of the "Master" class that many apps have -in this case your Game class. It typically needs to have access to everything else in the game, so is highy coupled. Whether the coupling from Game to Item is via Inventory or not doesn't look like a big issue here, so personally I'd stick to the structure shown in yor class diagram, at least until I found a reason not to.

Ok thanks, this code is partially based on code i already got, so i won't go and change it if it's not necessary

This question has already been answered. Start a new discussion instead.