就地用其他对象替换对象

发布于 2024-11-06 10:59:26 字数 255 浏览 2 评论 0原文

假设我想构建一个数据库抽象层,它使用延迟加载机制。

如果我要求该层加载根对象,它会加载其外部表示并构建自身。

然后它以某种方式识别出某些链接对象的存在。由于预先加载所有内容可能成本高昂,因此它为相关对象建立了代理。这样的代理应该能够被传递。

如果在这样的代理上调用第一条消息,它将加载其外部表示并构造自身。由于对代理的引用可能已被传递,因此创建的对象需要就地替换现有的代理对象。

我可以在 PHP 中用另一个对象就地替换一个对象吗?

Suppose I'd like to build a database abstraction layer, which uses a lazy loading mechanism.

If I ask the layer to load a root object, it loads its external representation and constructs itself.

It then somehow identifies that certain linked objects exist. Since it might be costly to load all up-front, it established proxies for related objects. Such proxies should be able to get passed around.

If a first message is called on such a proxy, it loads its external representation and constructs itself. Since references to the proxy may have been passed around, the created object needs to replace the existing proxy-object in-place.

Can I in-place replace an object with another object in PHP?

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

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

发布评论

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

评论(1

淡淡離愁欲言轉身 2024-11-13 10:59:26

I don't believe it's possible for an object to replace all references to itself with another object. Instead, have your proxy objects forward property access and method invocation using overloading. Implement proxying on a base proxy object (named e.g. OOProxy), then extend this to a LazyProxy class that lazily loads the proxied object. As long as you don't need to examine the type of the object, anything that has a reference to the proxy won't be able to distinguish it from the proxied.

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