How does JavaFX handle cyclic property bindings? -
assume have following code snippet:
private final booleanproperty = new simplebooleanproperty(false); private final booleanproperty b = new simplebooleanproperty(false); private final booleanproperty c = new simplebooleanproperty(false); private final booleanproperty d = new simplebooleanproperty(false); a.bind(c); c.bind(d.or(a));
how javafx handle that? because dependent c, c dependent on d or a). there formula recognize such 'exceptions'?
my first thought property_a cant bound property_b bound property_a or depends on properties too, have properties bound property_a. right?
javafx not prevent kind of dependency.
there no cycle in dependencies , in case allowed. analyzing dependencies not possible, since bind
takes observablevalue
parameter, regardless of implementation , internals of implementation hidden "behind interface", it's impossible dependencies observablevalue
.
it's therefore programmer ensure no circular dependency created.
modifying d
leads stackoverflowerror
.
you can identify kind of issue, if analyze "depends on" relation (the transitive closure needs irreflexive), need store information dependencies in custom data structure (or analyze "by hand" before compiling).
a directed graph suitable store kind of information , assuming prevent circular dependencies being established, can depth first search of dependencies property want bind. (dfs enough, since dependency graph forest.)
in case after a.bind(c)
graph contain single edge:
a -> c
before doing c.bind(d.or(a))
need search nodes d
, a
dependencies c
, since want add following edges:
c -> d c ->
now d
isn't bound, can go a
c
, property
want bind to, dependency should not created.
Comments
Post a Comment