This week's book giveaway is in the Open Source forum.
We're giving away four copies of Programmers Guide to Apache Thrift and have Randy Abernethy on-line!
See this thread for details.
Win a copy of Programmers Guide to Apache Thrift this week in the Open Source forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Bind Fields/Vars together?  RSS feed

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there  - suppose I have:



is there any way to set up a binding between x and y so that if one changes, the other changes to the same value and vice-versa? This is a major simplification of the actual code/design, but if i could get this specific answer, it would be very helpful.

THANKS!
 
Marshal
Posts: 64473
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Find out what the current state of the Observer Pattern is. I don't know much more than that, I am afraid.
 
Saloon Keeper
Posts: 3250
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can work with bound properties. See here for an explanation:
beans properties
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Ranch Hand
Posts: 161
5
MS IE Notepad Suse
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
although it seems easy possible - it kinda seems code smell - if you want to entangle fields - then why just don't use a single field?
try to keep the same or dependent information is quite error prone - if possible the base data should kept only once and the dependent data should be evaluated at the time they're needed (aka in getters used to retrive dependent data instead of direct field access)
 
Marshal
Posts: 5980
155
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that JavaFX has a load of Observable classes, such as ObservableIntegerValue, but I don't know if they work outside of the JavaFX environment.  Also, it would tie your code to Java 8 unless you import the JavaFX base. (JavaFX is no longer packaged with Java 9 and above).
 
Piet Souris
Saloon Keeper
Posts: 3250
128
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is a very interesting suggestion by Knute. I have no experience with JavaFX and its binding possibilities, time for me to try some things out!!

But here is a silly exapmple how you could do such a thing in Java:
 
joseph hu
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Observer Pattern  example

en.verejava.com/?id=20065053707352
 
Campbell Ritchie
Marshal
Posts: 64473
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately, the classes used by that last example have been deprecated.
 
joseph hu
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can create Observer class by yourself.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!