是否值得在 PHP 中实现观察者模式?

发布于 2024-08-26 10:25:04 字数 1431 浏览 3 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

一身仙ぐ女味 2024-09-02 10:25:04

对于一种编程语言来说,这是一个有点奇怪的问题,它在设计上不共享任何内容,并且无论如何都会根据每个请求重新创建整个环境。

在谈论成本时,您必须考虑到在每个请求上查找和重新创建会话数据也会占用资源。我不知道我们在您的应用程序中讨论了多少关系,但在引导程序中将所有必需的主题与观察者附加在一起对我来说听起来是一种干净有效的方法。您可以将此责任推入经理类以提高可维护性。

如果对性能有疑问,请进行基准测试。

That's a somewhat odd question to ask for a programming language that - by design - shares nothing and recreates the entire environment on each request anyway.

When talking about cost, you have to take into account that finding and recreating the session data on each request takes up resources too. I don't know how many relations we are talking about in your app, but attaching all required subjects with observers in a bootstrap sounds like a clean and valid approach to me. You could push the responsibility for this into a manager class for increased maintainability.

If in doubt about performance, benchmark.

Saygoodbye 2024-09-02 10:25:04

重新建立关系本身可能会花费最少的时间,因为对象是作为引用传递的。

The recreation of the relationships themselves would probably take the least amount of time, since the objects are passed around as references.

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