获取更改命令而不修改集合

发布于 2024-10-14 01:09:38 字数 505 浏览 10 评论 0原文

可能是一个命名很糟糕的标题,但无论如何......

我正在分层数据集上使用命令模式。所以基本上我需要一个返回一个对象的方法,该对象描述在不实际更改数据的情况下将进行的更改。例如:

对象 1 ->对象2->对象 3

如果我移动对象 1,则会导致对象 2 发生变化,从而导致对象 3 发生变化,因为它们相互依赖。所以...我需要一种方法来递归地遍历分层集合并收集移动对象 1 所需的更改,而无需实际修改集合。在递归进行到一半时,如果能够使用像 Object1.Location 这样的东西就好了,但它可能已经计划进行更改,所以我无法可靠地使用它。

我觉得有很多算法需要进行这种类型的“就地”修改。作为一名非计算机科学专业的学生,​​我对此类事情了解不多,所以我什至不知道要寻找哪些搜索词来找到“解决方案”。我将解决方案放在引号中,因为我意识到我的问题可能没有直接的解决方案,但我只是在寻找一些好的指南/示例来让我的大脑运转起来。

任何人都可以提供一些正在做的此类事情的真实示例吗?提前致谢。

Probably a very poorly named title, but anyway...

I am using the command pattern on a hierarchical data set. So basically I need a method that returns an object that describes the changes that will be made without actually changing the data. So for example:

Object 1 -> Object 2 -> Object 3

If I move object 1, it will cause a change in Object 2, which will cause a change in Object 3 because they depend on each other. So...I need a method to recursively go through the hierarchical collection and gather up the changes that are required to move Object 1 without actually modifying the collection. Halfway through the recursion it would be nice to be able to use something like Object1.Location, but it may already slated for change so I can't reliably use it.

I feel like there are plenty of algorithms and such that need to do this type of "in place" modification. As a non-CS major I didn't learn much of this type of thing, so I don't really even know what search terms to look for to find a "solution". I put solution in quotes because I realize there probably isn't a direct solution for my problem, but I am merely looking for some good guidelines/examples of this being done to get my brain cranking.

Can anyone provide some real-world examples of this type of thing being done? Thanks in advance.

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

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

发布评论

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

评论(1

人间不值得 2024-10-21 01:09:38

解决方案的一部分可能是访问者模式。您可以与访问者一起浏览对象树,并执行诸如生成“克隆”树之类的操作,该树代表您想要执行的操作的结果......

您能给我们一个您想要实现的示例吗?

我的2c

Well part of the solution might be the visitor pattern. You can go through your object tree with the visitor and do something like generating a "cloned" tree representing what will be the result of what you want to do ...

Can you give us an example of what you want to achieve ?

my2c

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