• Post Reply Bookmark Topic Watch Topic
  • New Topic

Class update dependency  RSS feed

 
Bryan Murphs
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my program classA, and this class needs to be aware and update itself whenever classB changes state, what’s the best way to implement this?
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider making class B an Observable, and class A an Observer.
 
Suhrid Karthik
Ranch Hand
Posts: 58
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wikipedia has a nice entry on the Observer pattern which includes a Java code example as well.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!