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 8928509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:27:14+00:00 2026-06-15T08:27:14+00:00

I don’t know if this is right place. But I need answer very much.

  • 0

I don’t know if this is right place. But I need answer very much.

I’m writing program for tournament management. I have simple problem but for me it is not that clear.

There are many clubs (One club from one city). There are players in club. There are no players without club.

I have Player class and Club class.
Should I keep list of players in Club class or keep players club in his class?
Which way would be better?

  • 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-06-15T08:27:15+00:00Added an answer on June 15, 2026 at 8:27 am

    Since every Player has a Club, keep a list of Players in the Club class. This makes it fast and simple to enumerate or search all Players in a given Club. However, there’s no reason you can’t also have a reference in the Player class which points to its parent Club. There are valid use cases for having a link in each direction, so do both.

    I’m assuming that each Player can only belong to one Club. Things will get a bit more complicated if that is not the case.

    An example in C#: (not compiled / tested, so it may have some minor errors)

    public class Club
    {
       // other class members
    
       // this is private so that code must use Club's methods to get at the Players
       private List<Player> _players;
    
       public int PlayerCount
       {
          get
          {
             return _players == null ? 0 : _players.Count;
          }
       }
    
       public void AddPlayer(Player p)
       {
          // null checking etc
          // here you could enforce a rule that p.ParentClub must be null
          // to prevent a Player from being in multiple Clubs
          p.ParentClub = this;
          _players.Add(p);
       }
    
       public void RemovePlayer(Player p)
       {
          // null checking etc
          _players.Remove(p);
          p.ParentClub = null;
       }
    }
    
    public class Player
    {
       // other class members
    
       public Club ParentClub 
       { get; set; }
    }
    

    Now, you can do things like this:

    // add Player Joe to the London Club if it is not full (10 members max)
    // otherwise add Joe to the Munich Club
    if(londonClub.PlayerCount <= 10)
    {
       londonClub.AddPlayer(joePlayer);
    }
    else
    {
       munichClub.AddPlayer(joePlayer);
    }
    
    // print how many players are in the club that Joe is in
    Console.WriteLine("Number of Players in Joe's Club: " + joePlayer.ParentClub.PlayerCount.ToString());
    
    // move Joe to the Amsterdam club. Note that it does not matter what Club Joe was already in
    joePlayer.ParentClub.RemovePlayer(joePlayer);
    amsterdamClub.AddPlayer(joePlayer);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know if this is the right place to ask this, but I will
Don't need to do this right now but thinking about the future... What would
I don't know why, but this code worked for me a month ago... maybe
Don't know why this is happening, but after submitting a form via JS (using
Don't know if I worded the question right, but basically what I want to
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know if this is an eclipse specific problem but whenever I declare a
Don't know if I'm over-thinking this or not.. but I'm trying to be able
Don't ask me why but i can't use this method because I need to
Don't know why but I can't find a solution to this. I have 3

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.