Automatically executing code whenever a variable is updated
Say I have a program that contains some data.  Some integer values, e.g. {1, 5, 10, 3}.  The program has a GUI that displays the data.  Each integer is converted to string and displayed as a label.  There are several different parts of the program where the data can be changed, e.g. a button that increments a value when clicked.  Each time a value changes the corresponding label must be updated to display the new value.

Perhaps a more common senario: say we have a control that both changes data and displays data, e.g. a slider bar.  Each time the slider is moved we want the data to change, and be displayed in a label (or maybe many different labels).  But there are also other ways the data can change, and when it does the slider bar should move.

For Java Swing, what is the current best practise for doing this automatically so we don't ever forget to update the labels?

Same question for Objective C Cocoa.

Automatically executing code whenever a variable is updated
===

Say I have a program that contains some data.  Some integer values, e.g. {1, 5, 10, 3}.  The program has a GUI that displays the data.  Each integer is converted to string and displayed as a label.  There are several different parts of the program where the data can be changed, e.g. a button that increments a value when clicked.  Each time a value changes the corresponding label must be updated to display the new value.

Perhaps a more common senario: say we have a control that both changes data and displays data, e.g. a slider bar.  Each time the slider is moved we want the data to change, and be displayed in a label (or maybe many different labels).  But there are also other ways the data can change, and when it does the slider bar should move.

For Java Swing, what is the current best practise for doing this automatically so we don't ever forget to update the labels?

Same question for Objective C Cocoa.
