• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unique data instances

Jez Nicholson
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe i'm missing something fundamental in my view of OO. I'll try to keep this simple....

  • I have a Swing app where I can open a number of panels/views.
  • I have a User instance 'Harry' in a tree, I double-click to open a panel and pass in the instance.
  • If I change an attribute of 'Harry' via a panel then I will have changed the instance that is also referenced by the tree...they're in synch..and i'm happy.
  • In another panel I do a database query to retrieve all Users, 'Harry', 'John' and 'Sarah', instantiate new objects to represent them and show them in a panel. I now have an instance for 'Harry' in the tree and an instance in my new panel.

  • How do I ensure that either a) I only ever have a single instance for any one thing, b) changes made to one instance are done to the other(s), or c) I don't rely on unique instances?
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic