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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:29:44+00:00 2026-05-26T00:29:44+00:00

I am currently creating a big project, and as such I would like to

  • 0

I am currently creating a big project, and as such I would like to have everything worked out very well and as efficient as possible.

In my project, I have a class called Teams, which contains a HashMap(Integer, Team) of Team objects. Each instance of Team has a unique ID (integer).

There is also an object called Player. Each instance of Player can be assigned to a Team (but not always).

Now, I wonder what the best approach would be to know what Team a Player is assigned to:

-> Store the ID of the team in Player (private int team), this ID is then used to get the Team from the HashMap in Teams.

-> Store a reference to the Team in Player (private Team team)

Does anyone know which is better, and what the most important pro’s, con’s and dangers are of each?

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-26T00:29:45+00:00Added an answer on May 26, 2026 at 12:29 am

    Use private Team team! Other classes should not need to know the ID of an object unless there is a good reason. Don’t implement a Database structure in Java. Java is designed to be Object-based, use it that way.

    There are a couple additional reasons you should hold the Team instance:

    1. We can assume that your Player will need to access the Team object. It is better to have the instance rather than having to do a lookup.
    2. If you hold onto IDs instead of instances, there might not be any reference to an object being held and it could be garbage collected. I know that probably won’t happen in your case since you hold all Teams in a Map, but it is still a risk and therefore should be avoided.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently creating a user interface using WPF and would like to display a
I am working on a big .NET project. I am currently creating an automated
I am currently creating an e-commerce site using C# ASP.NET MVC and have just
I'm currently creating a small todo site, and I have multiple questions related to
I need to load a very big image on AS3 (currently sized at 8192x8192).
I am current in planning on creating a big database (2+ million rows) with
I'm currently creating an explicit reference to this in the outer class so that
I'm currently creating an application for a customer that will allow them to automatically
I'm currently creating a WinForm in VB.NET bound to an access database. Basically what
We are currently creating an InfoPath 2007 form is deployed in SharePoint 2007. In

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.