Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How do I implement an aggregation?

EdChouaffeDec 25 2011 — edited Dec 26 2011
Hi guys,

I was wondering how do I implement an aggregation in Java.
Here is the case:

Team has a 1 to N association to player.

First suggestion:
class Team{
      ArrayList<Player> players;
      ...
}

class Player{
...}
Second suggestion:
class Team{
      ArrayList<Player> players;
      ...
}

class Player{
    Team team
...}
My question is actually to know whether the objects of the class Player should know about the object Team that contains them.
I had a discussion about with a colleague of mine, and I really need to clear things up.
I personally tend for the first suggestion

Best regards.

Edmond
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 23 2012
Added on Dec 25 2011
2 comments
1,503 views