2 Replies Latest reply: Dec 26, 2011 12:20 AM by 906939 RSS

    How do I implement an aggregation?

    EdChouaffe
      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