Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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 ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Question Regarding MVC Approach

Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I'm looking primarily for non-technical replies it's more an opinion based post.

I have implemented the following approach:

// MVC Approach //
Class Model (observable)- holds the collection storing my data. Sets class GUI as an observer.
Class GUI (observer) - displays a table displaying the collection data

When changes are made in the model it uses the following code to alert its observers - setChanged() & notifyObservers().

The GUI implements the update method which is ran when notifyObservers is called, in the update method I call updates on the table to make it refresh.

Is this the correct way to implement MVC? I have heard rumors that my table should be directly observing the model and shouldn't need to call the repaint method.

I'm starting to get confused again so any advice appreciated.

Thank you
Ranch Hand
Posts: 15304
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Speaking specifically about JTable's....

You should create a TableModel and give this model to your JTable. Then you can modify the data in the table model which will notify the table when changes are made.

I think you are just overthinking it a bit. Your design would be good for components that don't really have a model and still need to be updated in some way (JTextFields, JLabels, etc).
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your model is used elsewhere in the system, you could also write an adapter that implements table model and uses your model for the actual data storage. Otherwise, I'm with Greg that just using tablemodel would be best.
Hang a left on main. Then read this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic