jeudi 9 mai 2019

Is the design pattern of JavaFX properties a worthwhile system to implement in different situations?

I recently had to program a simple project with JavaFX and I was fascinated by the property pattern.

In simple terms it is a huge wrapper hierarchy of classes that allow primitive (and non-primitive) values to be an observable with additional functions to create chains of operations on these observables to "bind" values of other properties to computations on these (non-)primitive values. A change to a bound property also causes changes to the binding property. Simple Listener/Observer stuff here.

While teaching programming classes one of the most definitive stuff we always need to do is to teach students that assignments of variables do no cause an equation-system to exist.

x = 3;
y = x + 2;
x = 5; // y is NOT 7

This binding system basically allows for such relationships to exist. It is different but nothing exceptional but it kind of blew my mind the first time I saw it because I have never yet encountered such a low level use for the observer-pattern.

Now what I wonder is if an implementation of such a system is actually worthwhile or considered an antipattern in different systems. Would a generalized API in other programming languages like C++ actually find productive use? Does something like that already exist in most programming languages and I simply do not know what to call it to find resources for it?

As it is a "Java Bean" thing I kind of expect people to scream "Property Bindings considered harmfull!"

Aucun commentaire:

Enregistrer un commentaire