Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The design pattern you are looking for is: Differential Execution. I do believe.</p> <p><a href="https://stackoverflow.com/questions/371898/how-does-differential-execution-work#381861">How does differential execution work?</a></p> <p>Is a question I answered that deals with this. </p> <p>However, may I suggest that you use a callback instead? You will have to read about this, but the general idea is that you can implement interfaces (often called listeners) that active upon "something interesting" happening. Such as having a data structure be changed.</p> <p>Obligitory links:</p> <p><a href="http://en.wikipedia.org/wiki/Differential_execution" rel="nofollow noreferrer">Wiki Differential execution</a></p> <p><a href="http://en.wikipedia.org/wiki/Callback_(computer_science)" rel="nofollow noreferrer">Wiki Callback</a></p> <p>Alright, here is the answer as I see it. Differential Execution is O(N) time. This is really reasonable, but if that doesn't work for ya Callbacks will. Callbacks basically work by passing a method by parameter to your class that is changing the array. This method will take the value changed and the location of the item, pass it back by parameter to the "storage class" and change the value approipriately. So, yes, you have to back each change with a method call. </p> <p>I realize now this is not what you want. What it appears that you want is a way that you can supply some kind of listener on each variable in an array that would be called when that item is changed. The listener would then change the corresponding array in your "backup" to refect this change. </p> <p>Natively I can't think of a way to do this. You can, of course, create your own listeners and events, using an interface. This is basically the same idea as the callbacks, though nicer to look at.</p> <p>Then there is reflection... Java has reflection, and I am positive you can write something using it to do this. However, reflection is notoriously slow. Not to mention a pain to code (in my opinion). </p> <p>Hope that helps...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload