观察者模式过载
我陷入了以下场景。它有一种代码味道,我对此不满意,但它的解决方案似乎很复杂,但只是以不同的方式。
我有一个代表业务对象的场景图。我对其进行设计,使业务对象本身尽可能简单。它们实际上是 POJO。
现在,1 个实体可能通过不同的节点显示在场景图的多个区域中。
当实体发生变化时,所有相关的场景图节点都应该发生变化。
我犹豫是否要在所有实体上使用观察者模式,因为屏幕上同时显示超过 50000 个实体。
由于所有更改都是从视图启动的,因此现在我正在场景图上递归并强制重新加载与更改的实体关联的所有节点。但感觉不太对劲。
关于如何做得更好有什么建议吗?
I'm stuck with the following scenario. It has a code smell, that I'm not happy with, but resolutions to it seems to be as complex, but just in different ways.
I have a scene graph representing business objects. I've designed it so that the business objects themselves are as simple as could be. They're practically POJOs.
Now, 1 entity might be displayed in multiple regions of the scene graph by different nodes.
When the entity changes, all relevant scene graph nodes should change.
I'm hesitant to use the observer pattern on all my entities since I have over 50000 entities on screen at one time.
Since all changes are initiated from the view, right now I'm recursing over the scene graph and forcing a reload of all nodes associated with the changed entity. Doesn't feel right though.
Any suggestions on how this could be done better?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
业务对象==实体?其中 50k 个实体在屏幕上表示为节点,其中一些实体具有多个节点。用户操作会改变实体的状态,因此必须更新某些节点。但实体当然不知道节点。
我会让代理对象包装实体。他了解与节点的关系。实体的更新通过他来完成,因此他可以完成更新,然后通知相关节点。实际上,这避免了必须迭代节点集来寻找更新。
Business Object == Entity? You have 50k of them represented as nodes on the screen, with some entities having more than one node. A user action chages the state of the entity and hence some nodes must be updated. But of course Entities don't know about nodes.
I would have proxy object wrapping the Entity. He understands the relationship to the Nodes. Updates to the entity go via him, hence he can complete the update and then notify the relevent nodes. Effectively this avoids having to iterate the set of nodes looking for updates.
实体应将其更新发布到单个队列中,然后负责更新视图的对象可以轮询该队列。
The entities should post their updates into a single queue, which can then be polled by the object responsible for updating the view.