title: Wrapping Collection Elements
body: <p>This is a design question and I'm going to frame it as clearly as possible, but I'm not really sure what to call the problem I'm facing.</p>
  
  <p>I'm working on a video game, and setting up and playing the game involves multiple steps. I wanted to wrap each of these steps in some sort of object, to keep everything clean.</p>
  
  <p>I chose to split up the flow of the game into sessions, rounds and spawns. A session of the game is the highest scope level, you configure which players are active (through a join screen) then proceed to start a round. You can play multiple rounds within a single session, and each of those rounds will inherit the global session data. Likewise, you can die and respawn multiple times in each round, inheriting data from both the round and the session.</p>
  
  <p>So imagine somesort of free.</p>
  
  <ul>
  <li>Session 1</li>
  <li>Session 2
  <ul>
  <li>Round A</li>
  <li>Round B
  <ul>
  <li>Spawn 1</li>
  <li>Spawn 2</li>
  </ul></li>
  <li>Round C</li>
  </ul></li>
  <li>Session 3</li>
  </ul>
  
  <p>Spawn 1 will have access to data from Round B and Session 2.</p>
  
  <p>This seems like a pretty clean design. I can keep the session-wide data in one place and keep that object alive through the entire session, with each round branching off and inheriting this data.</p>
  
  <p>Now the interesting issue. Like I said before, the session contains a collection of players (the ones that joined the game and are active during the whole session). The round ALSO needs to keep some additional data about each player, but that data only exists inside a round (the last spawn point for instance, or the current score). I wanted to follow the same pattern and create another class, which would hold this round-specific data.</p>
  
  <p>Where this breaks down is when maintaining the collections. Because the session contains the authoritative list on players, and each round provides additional add-on data, should the round just update a member of the SessionPlayer? Should the round have its own list of players, each with the round-level data and a pointer up to the session-level data? Should they contain separate collections with matching ids?</p>
  
  <p>This seems like something that could be solved with a clever design pattern, but I haven't been able to find one.</p>
  
  <p>To summarize: How to temporarily wrap an object containing a collection, while wrapping all the elements of that collection as well?</p>
  
  <p>I hope I explained that properly. Thanks for the help!</p>