MVC模型关系:如何避免模型的多个实例?

发布于 2024-12-20 00:13:32 字数 187 浏览 2 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最舍不得你 2024-12-27 00:13:32

最常用的模式可能是身份映射

The pattern that is probably going to be of the most use is the Identity Map.

撩起发的微风 2024-12-27 00:13:32

如今颇有争议,但 Singleton 也可能是你的朋友。

Pretty controversial nowadays, but Singleton might also be your friend.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文