Reputation: 3975
I have to develop a Swing Project. I need to access the database in various places. So how should I arrange the classes so that there is one database class. Should I use inheritance for that. Just a brief outline. I'm a java(struts/spring/hibernate) developer but its going to be my first Swing Application.
Upvotes: 2
Views: 485
Reputation: 76436
A few ideas:
I think you should use an ORM (like OrmLite, for example) in your application
Create a package which will contain interfaces or abstract classes for your data access layer.
Create another package where your interfaces and abstract classes (of the data access layer) are implemented (these implementations should contain all your direct commands to the database)
Create another package, where you will have your business layer. The methods of your classes in this package should use the data access layer through the interfaces and combine them to solve any business-logic-level problem
You should access directly your business layer classes from the backend part of your application which should be separated from your user interface as much as possible
Upvotes: 5
Reputation: 285403
Inheritance? No, rather you'd use composition. Accessing a database is no different for a Swing application than a non-Swing application with a few caveats:
Upvotes: 7