Object Oriented / App Design Question

G

Guest

I am designing a web application in asp.net C#, and I created classes (in
..cs files) working with the .aspx pages. Now, for database part....
wondering which way is better:

1. put database connectivity in the Classes, each class has the load/save
data method? Many of my classes are inherited from each other, and since I
am using SQL 2000 which is a relational database makes the job little bit
more complicated.

2. put database connectivity in .aspx pages, then get/put the data from/into
the classes when needed? This sounds easier, but is it a bad design?

Any suggestions are welcome.. thanks
 
H

Hermit Dave

OOAD normally involves slightly more work but has great deal of advantages
in terms of breaking the system down into manageable chunks.

Consider a page where you have user login, registration, profile view and
edit etc. They all related to all users and potentially have independant UI.
So you would have say 4 aspx pages with code behind. But to directly access
the database from those codebehind classes doesnt help code reuse like if
you needed the same data somewhere else.. in that case you would be
repeating the code. So you create a Middletier which essentially channels
call. So all you aspx pages would do is call the middle tier class to get
the data..

The middle tier classes could implement the logic to connect to the database
and fetch the data which you return to the calling function. that way your
aspx page is not way concerned on whether you are using access or sql server
or msde or oracle or sybase. You could go further and use generic data
access block like the one from MS which lets you connect and do queries on
ms sql 7 or above. That way if you change the database all you have to
change is the middle-tier and replace the calls with new library class..

ASPX ==> codebehind for presentation logic >> Middle tier >> Data Access
Tier >> Database. Read up a bit on layed / tiered application design..

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
 
C

Cowboy \(Gregory A. Beamer\)

I am not sure I like either. One methodology that works well is the creation
of a persistance layer that controls marshalling the business objects from
the database to your app. You have methods in the class that force the
callback, but the object-relation mapping engine (persistence layer part) is
actually aware of how to get the data back. This is a better OO design, and
you can find examples on open source sites like SourceForge (including
code).

Rockford Lhotka has his own design of a data "persistance" type of engine
that looks promising. It is in both his VB.NET and C# objects books. You can
download the code and adopt it for your site.

Finally, ObjectSpaces will be out in a future Visual Studio. It allows
mapping via an XML Schema. Unfortunately, it has been dumped from Whidbey
timeframe, but you can still get the March preview and play around with the
idea. If you can get a similar method, you will be ready when objectspaces
are finally available.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside the box!
*************************************************
 
G

Guest

Does that mean option (1) is better? To be specific, the Classes I wrote
can be act as middle tier, and they all get compiled as .dll put in the
/bin.
 
H

Hermit Dave

well there are lots of techniques and all have their advantages and
disadvantages. What you use is based on
a. how much seperation you want
b. the hassle you wouldnt mind going into.

I would say that option 1 isnt bad... though you could still drill further
down to increase the seperation.

consider thing.. from every class that access database you will start by
getting the connection string and creating a connection etc. You break that
down further but you have to decide on factors A & B.

You want to look up on what Greg mentioned as well..

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
 

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

Members online

Forum statistics

Threads
473,771
Messages
2,569,587
Members
45,097
Latest member
RayE496148
Top