将两个单独的结构同步到相同的主数据

发布于 2024-08-28 09:13:33 字数 524 浏览 3 评论 0原文

我的应用程序中有多个结构需要维护。所有链接都指向相同的记录,其中之一可以被视为“主记录”,因为它反映了磁盘上文件中保存的实际关系。其他结构用于“调用”采购和工作订单的主要设计元素。我正在努力想出一种适当处理主数据更改的模式。

例如,以下树可能引用相同的数据:

A
|_
  B
  |_ 
    C
    |_
      D
|_
   E
   |_
     B
     |_
       C
       |_
         D


A
|_
   B
   E
C
|_
  D

A
|_
  B
  C
  D
  E

这些二级结构遵循内部规则,但它们的整体结构通常是用户确定的。在所有情况下(包括主节点),任何元素都可以在多个位置和多个树中使用。当我向树中的任何元素添加子元素时,我想自动为“主”元素的每个实例构建二级结构,或者至少向用户通告这种情况,并允许他们手动生成该元素所需的数据。次生树。

有什么模式可以适用于这种情况吗?我一直将其视为视图问题,但事实证明,当您查看数据的初始生成时,它比这更复杂。

I've got multiple structures to maintain in my application. All link to the same records, and one of them could be considered the "master" in that it reflects actual relationships held in files on disk. The other structures are used to "call out" elements of the main design for purchase and work orders. I'm struggling to come up with a pattern that deals appropriately with changes to the master data.

As an example, the following trees might refer to the same data:

A
|_
  B
  |_ 
    C
    |_
      D
|_
   E
   |_
     B
     |_
       C
       |_
         D


A
|_
   B
   E
C
|_
  D

A
|_
  B
  C
  D
  E

These secondary structures follow internal rules, but their overall structure is usually user-determined. In all cases (including the master), any element can be used in multiple locations and in multiple trees. When I add a child to any element in the tree, I want to either automatically build the secondary structure for each instance of the "master" element or at least advertise the situation to the user and allow them to manually generate the data required for the secondary trees.

Is there any pattern which might apply to this situation? I've been treating it as a view problem, but it turns out to be more complicated than that when you look at the initial generation of the data.

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

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

发布评论

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

评论(1

み零 2024-09-04 09:13:34

树的实现应该是一个很好的起点。主副本将是完整的树。

副本中的节点可以是复合对象,其中包含数据和对主树中相应节点的引用。

当添加子节点或在其中一个副本中的节点上发生任何其他修改时,该节点可以向主树发送一条消息,其中包含主树中相应节点的引用以及更改的详细信息。

然后主服务器会修改自身并更新其他副本。

事件处理可能会变得棘手,因为您必须确保不使整个过程循环。

A tree implementation should be a good starting point. The master copy will be the complete tree.

The nodes in the copies can be composite objects that contain the data and a reference to the respective node in the master tree.

When a child is added or any other modification happens on a node in one of the copies, the node can send a message to the master tree with the reference of the corresponding node in the master tree and details of the change.

The master would then modify itself and update the other copies.

The event handling may get tricky because you will have to make sure to not make the whole process cyclic.

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