Best practices accessing data?

D

DelphiLover

Hi.

I'm reading and reading, testing and testing, trying to figure out how
to do things, how to do things according to best practises and how to
do things in the best object oriented way.

So... Best practises, in good object oriented fashion: how do I do it.

I'm thinking making classes for data access. An Example that ALL books
do - customer - and orders. So I'm thinking: Making a customer class
and a orders class. The customer class has methods for accessing the
customer table (or datasource of some kind) and it also has
functionality to get the related orders.

I can use generic factoring in the class, so this does NOT make my code
database specific.

Secondly I can put a ObectDataSource on my form, point it to my class,
tell it what functions will fill the dataset etc. (btw: do I need one
separate datasource for each of the functions I wanna point to in the
class... ?)

Then I connect the gridview to the object datasource to publish my data
to the user.

Well, does this sound like I'm on the right track.. ?
You wouldn't happen to have some code on how you do it.... ?

I will greatly appreciate a discussion about this!

Thanx,
Fritjolf
 
G

Greg Young

I would take a look at an OR mapper such as nhibernate, wilson or, lblgen,
etc.

What you are describing sounds a bit like active record ...

I might also suggest looking at the repository pattern where you seperate
the concern of managing the objects out of the bsiness object and into its
own object. As you said you can hack your way into database independence but
what if as an example you now need to read some customers from a webservice
or from a text file .. the customer class will quickly get crowded with
accessor methods.

There is a great example of customer/order using a repository in Jimmy
Nilsson's Applying Domain Driven Design and Patterns.

Cheers,

Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top