This discussion is archived
2 Replies Latest reply: Dec 25, 2011 10:20 PM by 906939 RSS

How do I implement an aggregation?

EdChouaffe Newbie
Currently Being Moderated
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

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points