我需要一种设计模式,用于在对象中存储对仅在需要时创建的其他对象的引用
一个很好的比喻是房子。那所房子有房间,所有这些房间都有人和物品。首先,我只需要知道房子存在并具有某些属性,但是当我进入一个房间时,我需要知道这些房间的内容。存储房屋、房间、人和物体之间的引用而不在内存中创建一堆对象的最佳方法是什么?
A good analogy is a house. That house has rooms, and all of those rooms have people and objects. To begin with I only need to know the house exists with certain properties, but when I enter a room then I need to know the contents of those rooms. What is the best way to store a reference between the house and the rooms and the people and objects without creating a bunch of objects in memory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
延迟加载。
这在 Hibernate/JPA 等系统中得到了广泛的实现和支持。
Lazy loading.
This is implemented and supported widely in for example Hibernate/JPA.