I’m trying to create an MVC application for managing sports teams and players using Zend Framework. A team has a list of players and each player belongs to only one team. The problem I have is with instantiating multiple individual players.
At the moment when I instantiate a single player, a new team object is always created even if I had instantiated a player that belongs to the same team earlier. How could I avoid unnecessary multiple instances that represent the same team? Is there some design pattern or technique that could be used here?
The pattern that is probably going to be of the most use is the Identity Map.