tags:

views:

103

answers:

3

I am making kind of CRUD application (Java GUI , MYSQL) Should I :

  • load data from database to List (for example) and then List to GUI
  • load data from database to Object(with attributes like SQL table) and Object to GUI

Am I just paranoid or is another object really needed?

A: 

In theory, you can do both, but choosing the second approach will make it much easier to add some non-basic features, like validation, later.

ammoQ
I do validation with SQL procedures mostly or just catch exceptions :D
miso
A: 

I guess it depends a lot on what are you going to do with the data, and how much of it there is.

E.g. if you are only going to show it on the GUI in some sort of tabular structure, you may not need objects. But if you want to present the data in a very non-tabular way, or you want to modify it, or there is also behaviour attached to the data, then objects are a better choice. Then again, if you are going to have to deal with 3 million rows in your table, you won't want to hog the memory with objects...

Péter Török
I actually make loads of table componenets
miso
You know, sometimes this happens to me ... I have like 60% project done and ask myself - inst it completely wrong? :))but actually it works good, but without additional objects looks bad with uml :/
miso
@miso I am a big fan of "do the simplest thing that could possibly work". UML is a nice thing, but to me it's just a design aid. I use it when I am stuck with a problem and need to visualize and arrange ideas in my head and/or discuss it with a colleague. And then I throw it away. At later stages it is more of a hindrance than a help.
Péter Török
Peter - I love to hear that, thanx.I guess I needn't to worry since it works :)And maybe rest more ... :D
miso
+2  A: 

Ideally to keep a strict separation of concerns you would want to keep the two models separate.

If you are developing an MVC (i.e. Model, View, Controller) rich-client application you would use a separate Model to bind to the GUI/form this is called the View Model which purpose is to present, capture and validate the data from a GUI. Ideally you would then copy this data into your Domain or Data Model which is the model you would persist.

It really depends on the application whether to go that extra mile or not, for 1-2 screen throw away apps that are just used to complete a simple task I don't really bother with it, but this approach really helps when developing large complex applications.

mythz
I dont know if it is large or not ...Currently 26 classes, approximatelly 50-70% doneDatabase is quite small = 12 tables atm
miso
If it's a read-only app I wouldn't bother but as it's a CRUD app I would consider it, it all depends on the usefulness and lifetime of the application and whether you need to continually improve it with added features. Since you're almost finished with your current approach it's a close call.
mythz
thanx for advices, question answered
miso