2

I am beginning to cover GUIs using JavaFX on my own and I was just curious as to how instances of ObservableValue can "monitor" a particular value for changes. It is an important concept for property binding but my book doesn't really explain how they accomplish this and I'm just curious.

Thanks.

Sam S.
  • 348
  • 1
  • 3
  • 15

2 Answers2

5

There is no magic behind the Observable types. Actually, it's really simple:

The only way to change the value of a *Property class from the outside is by it's setter method, which just triggers the listener.

vsakos
  • 492
  • 8
  • 19
4

It is an observer pattern you can read up on the observer design. If you want to find the specifics of how it is implemented in JavaFX, then study the JavaFX source, in particular the property source, a key class involved is the ExpressionHelper.

Community
  • 1
  • 1
jewelsea
  • 150,031
  • 14
  • 366
  • 406