Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 716555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:18:45+00:00 2026-05-14T05:18:45+00:00

I am learning a lot about design patterns when I am building my own

  • 0

I am learning a lot about design patterns when I am building my own system for my projects. 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. Right now I have three classes:

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

I have made a diagram to illustrate it:

I have a list of persons 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:18:45+00:00Added an answer on May 14, 2026 at 5:18 am

    The mutual dependency problem among the classes, strictly speaking, can be solved by using interfaces (abstract classes, if your language is e.g. C++ or Python) IRoom and IPerson; in pseudocode

    interface IPerson
        IRoom getRoom()
        // etc
    
    interface IRoom
        iter<IPerson> iterPerson()
        // etc
    

    this makes only the interfaces mutually dependent on each other — the actual implementations of the interfaces need only depend on the interfaces.

    This also gives you plenty of leeway in terms of implementation, if you want avoid circular reference loops (which can be a bother e.g. in CPython by slowing down garbage collections) — you could use weak references, an underlying relational database with a typical “one to many relationship” table, etc, etc. And for the first simple prototype you can use what’s simplest in your chosen language (probably simple, and alas necessarily circular, references [[pointers, in C++]] with a Person referring to a Room and a Room to a list<Person>).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning a lot about the Views in Drupal, but can't figure how to
I've had a lot of good experiences learning about web development on w3schools.com .
I'm learning about table design in SQL and I'm wonder how to create a
In a lot of the tutorials online for learning LINQ, they use a NorthwindDataContext.
Learning a little about T-SQL, and thought an interesting exercise would be to generate
Learning from my last question , most member names seem to get included in
I am new to programming (previously only did html/css/design) trying to start learning RoR
Learning WPF nowadays. Found something new today with .Net dependency properties. What they bring
Will learning C++ help me build native applications with good speed? Will it help
For learning and demonstrating, I need a macro which prints its parameter and evaluates

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.