Saturday, December 27, 2014

Observable: Reason for setChanged()

This is useful because it separates the part where you say that the Observable has changed, from the part where you notify the changes. (E.g. Its useful if you have multiple changes happening and you only want to notify at the end of the process rather than at each small step). This is done through setChanged().
- jbx http://stackoverflow.com/questions/13744450/interview-when-do-we-use-observer-and-observable

 ...setChanged is used like a flag I think. This is to avoid unnecessary updating
- James Poulson http://stackoverflow.com/questions/7271044/observable-in-java

But note possible race condition in Java's implementation of Observable where a second call to notifyObservers may not be completed and thus second parameter (if one is provided) is not sent. See answer by mab at http://stackoverflow.com/questions/4446718/why-observable-snapshot-observer-vector/11122611#11122611.

No comments:

Post a Comment