javafx - When use ReadOnlyProperty and when Binding -


there 2 kinds of read-only observable value: javafx.beans.binding.binding , javafx.beans.propety.readonlyproperty.

what difference in practical use? may listen both of them.

what interface should implement if want create read-only observable?

both interfaces, cannot instantiate either. in practice, either use concrete implementation of 1 of them (e.g. stringproperty, implementation of readonlyproperty, among other things, or subclass of stringbinding, implementation of binding), or call method returns one. when calling method, type is, of course, dictated return type of method.

the functional difference property wraps value typically implemented directly being stored in variable, whereas binding has dependency on 1 or more other values (and may computed "on-the-fly" required).

for example:

integerproperty x = new simpleintegerproperty(5); // property, stores value directly integerproperty y = new simpleintegerproperty(10); // property  // sum of x , y, observable, computed when required: integerbinding sum = new integerbinding() {     { super.bind(x, y); }     @override     public int computevalue() {         return x.get() + y.get() ;     } }; 

Comments