The sample design you are looking for is: Differential execution. I believe.
How is differential execution performed?
I asked a question to which I answered regarding this.
However, can I suggest using a callback instead? You will have to read about it, but the general idea is that you can implement interfaces (often called listeners) that are active on "something interesting." Such as changing the data structure.
Public relations:
Differential Wiki Execution
Wiki Callback
Ok, here is the answer I see. Differential execution is O (N) time. This is really reasonable, but if this does not work for you, Callbacks will be called. Callbacks basically work by passing a method by parameter to your class, which changes the array. This method will take the value changed and the location of the element, pass it back to the parameter in the "storage class" and change the value accordingly. So yes, you have to support every change with a method call.
I understand that this is not what you want. What seems right to you is a way that you can provide some kind of listener for each variable in the array that will be called when this element is changed. Then the listener will modify the corresponding array in your “backup” to edit this change.
I can’t figure out how to do this. Of course, you can create your own listeners and events using the interface. This is basically the same idea as callbacks, although it's better to look at them.
Then there is a reflection ... Java has a reflection, and I'm sure you can write something using this for this. However, reflection is known to be slow. Not to mention the pain in the code (in my opinion).
Hope this helps ...
source share