开发者

Database to GUI or Database to Object to GUI

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

  • load data from database to Li开发者_JAVA百科st (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?


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.


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.


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜