1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
   2 <html>
   3 <head>
   4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   5 <title>javafx.beans.binding</title>
   6 </head>
   7 <body>
   8         <h1>Characteristics of Bindings</h1>
   9         <p>Bindings are assembled from one or more sources, usually called
  10                 their dependencies. A binding observes its dependencies for changes
  11                 and updates its own value according to changes in the dependencies.</p>
  12         <p>Almost all bindings defined in this library require
  13                 implementations of {@link javafx.beans.Observable} for their
  14                 dependencies. There are two types of implementations already provided,
  15                 the properties in the package {@link javafx.beans.property} and the
  16                 observable collections ({@link javafx.collections.ObservableList} and
  17                 {@link javafx.collections.ObservableMap}). Bindings also implement
  18                 {@code Observable} and can again serve as sources for other bindings
  19                 allowing to construct very complex bindings from simple ones.</p>
  20         <p>Bindings in our implementation are always calculated lazily.
  21                 That means, if a dependency changes, the result of a binding is not
  22                 immediately recalculated, but it is marked as invalid. Next time the
  23                 value of an invalid binding is requested, it is recalculated.</p>
  24         <h1>High Level API and Low Level API</h1>
  25         <p>The Binding API is roughly divided in two parts, the High Level
  26                 Binding API and the Low Level Binding API. The High Level Binding API
  27                 allows to construct simple bindings in an easy to use fashion.
  28                 Defining a binding with the High Level API should be straightforward,
  29                 especially when used in an IDE that provides code completion.
  30                 Unfortunately it has its limitation and at that point the Low Level
  31                 API comes into play. Experienced Java developers can use the Low Level
  32                 API to define bindings, if the functionality of the High Level API is
  33                 not sufficient or to improve the performance. The main goals of the
  34                 Low Level API are fast execution and small memory footprint.</p>
  35         <p>Following is an example of how both APIs can be used. Assuming
  36                 we have four instances of {@link
  37                 javafx.beans.property.DoubleProperty} {@code a}, {@code b}, {@code
  38                 c} , and {@code d}, we can define a binding that calculates {@code a*b
  39                 + c*d} with the High Level API for example like this:</p>
  40         <p>{@code NumberBinding result = Bindings.add (a.multiply(b),
  41                 c.multiply(d)); }</p>
  42         <p>Defining the same binding using the Low Level API could be done
  43                 like this:</p>
  44         <pre>
  45 <code>
  46 DoubleBinding foo = new DoubleBinding() {
  47 
  48     {
  49         super.bind(a, b, c, d);
  50     }
  51 
  52     @Override
  53     protected double computeValue() {
  54         return a.getValue() * b.getValue() + c.getValue() * d.getValue();
  55     }
  56 };
  57 </code>
  58 </pre>
  59 </body>
  60 </html>