which is the best practice? That all depends on context.
There are 3 primary approached to accessing data.
1. transaction scripts
2. Data Table Gateways
3. Domain Mapping
depending on the complexity and needs of a context will determine which is the best approach.
transaction scripts are usually monolithic sql statements. stored procedures are the first thing that come to mind, but not the only type of scripting. This works well with simple/no logic when entering data into the database, ETL procedures and reporting.
data table gateways have a single domain object mapped to table. this object has commands which work against a single or set of rows for the table it's mapped to. If your domain objects have a 1:1 mapping with the database this can be a good approach. The most common implementation of this pattern is the ActiveRecord pattern. the .net framework also has an implementation of this in the form of DataSets and DataTables with DataAdapters.
Domain mapping is the most complex approach and is best suited when the domain is complex. there is not a 1:1 mapping of domain objects to database tables. example include accounting and logistics. the idea is your domain objects are suited to service the business problem. they don't have any knowledge of the database. To map the domain objects to the database you have another set of objects responsible for that. if your domain heavily leverages the patterns and practices of OOP then Domain Mapping is an excellent choice. the 2 biggest frameworks I have seen that solve this problem are Hibernate (java) and Nhibernate (.net)
the book
Patterns of Enterprise Application Architecture details these 3 approaches to data access. I highly recommend this as part of your research.
One other note. if you are dealing with any of the major programming languages (.net, java, ruby, php) then your data access problems are already solved. There are a number of commercial and open source frameworks which implement these concepts. It would need to be an extremely edge case to require you to create a data access layer from scratch.
as to whether your classes should be 1 super class or use inheritance. I would favor composition over inheritance whenever possible. I would ask the question do you want a single object to manage the domain and database operations, or do you want to separate these concerns. Depending on the complexity of the domain and the context for which it's used will determine the best approach.
Jason Meckley
Programmer
Specialty Bakers, Inc.
faq855-7190
faq732-7259