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.
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
精彩评论