Model relationships MVC: how to avoid multiple instances of models?

I am trying to create an MVC application for managing sports teams and players using the Zend Framework. The team has a list of players, and each player belongs to only one team. The problem is creating several separate players.

At that moment when I create an instance of one player, a new team object is always created, even if I created an instance of a player belonging to the same team earlier. How could I avoid unnecessary multiple instances representing the same command? Is there any design pattern or technique that can be used here?

+4
source share
2 answers

The template that is likely to be most useful is the Identity Map .

+3
source

Pretty controversial at the moment, but Singleton can also be your friend.

0
source

Source: https://habr.com/ru/post/1384995/


All Articles