MVC模型关系:如何避免模型的多个实例?
我正在尝试使用 Zend Framework 创建一个 MVC 应用程序来管理运动队和运动员。一支球队有一份球员名单,每个球员只属于一支球队。我遇到的问题是实例化多个单独的玩家。
当我实例化单个玩家时,即使我之前实例化了属于同一团队的玩家,也会始终创建一个新的团队对象。如何避免代表同一团队的不必要的多个实例?这里可以使用一些设计模式或技术吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最常用的模式可能是身份映射。
The pattern that is probably going to be of the most use is the Identity Map.
如今颇有争议,但 Singleton 也可能是你的朋友。
Pretty controversial nowadays, but Singleton might also be your friend.