2

I'm using ResultSets to create my DefaultTableModel, so I'm thinking that it might be good to avoid using ResultSets in the view, where the DefaultTableModel populates my JTables. I suspect my reasoning is wrong, guessing that Swing components belong to the view only, but am curious if such separation would prove valuable in some cases. I think the way the ResultSet is presented potentially alters the meaning of the information shown, making it more information based that presentation based.

So, if I have a Swing DefaultTableModel, is it ever appropriate to remove it from the view and place it in the model?

1 Answers1

2

It is appropriate to create a subclass of DefaultTableModel that accepts a ResultSet and does all the necessary processing. This way, the ResultSet is not directly exposed to the view so it gives you better encapsulation.

Maroun Baydoun
  • 454
  • 3
  • 8
  • Thank you, interesting! However, I was thinking of having a static method somewhere in the model that would return a DefaultTableModel instead. There reason being that I actually don't need to add or override anything in the DefaultTableModel, so I would consider this incorrect use of inheritance. I'm probably wrong, though! That's usually the case. –  May 01 '13 at 11:57
  • 1
    @talt: [*Item 1: Consider static factory methods instead of constructors*](http://www.drdobbs.com/jvm/creating-and-destroying-java-objects-par/208403883). – trashgod May 01 '13 at 16:26