Two objects with dependencies for each other. Is that bad?

Posted by Kasper Grubbe on Stack Overflow See other posts from Stack Overflow or by Kasper Grubbe
Published on 2010-04-11T02:39:13Z Indexed on 2010/04/11 2:43 UTC
Read the original article Hit count: 317

Hi SO.

I am learning a lot about design patterns these days. And I want to ask you about a design question that I can't find an answer to.

Currently I am building a little Chat-server using sockets, with multiple Clients. Currently I have three classes.

  • Person-class which holds information like nick, age and a Room-object.
  • Room-class which holds information like room-name, topic and a list of Persons currently in that room.
  • Hotel-class which have a list of Persons and a list of Rooms on the server.

I have made a diagram to illustrate it (Sorry for the big size!): http://i.imgur.com/Kpq6V.png

I have a list of players on the server in the Hotel-class because it would be nice to keep track of how many there are online right now (Without having to iterate through all of the rooms). The persons live in the Hotel-class because I would like to be able to search for a specific Person without searching the rooms.

Is this bad design? Is there another way of achieve it?

Thanks.

© Stack Overflow or respective owner

Related posts about oop

Related posts about object-oriented-design