Thursday, March 29, 2012

Object Oriented / App Design Question

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.. thanksOOAD 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)
"NOSPAM" <nospam@.xsagfgsagsafg.com> wrote in message
news:OsCdnXI8-P3i_cncRVn-tA@.rogers.com...
> 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
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!
*************************************************
"NOSPAM" <nospam@.xsagfgsagsafg.com> wrote in message
news:OsCdnXI8-P3i_cncRVn-tA@.rogers.com...
>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
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.

"Hermit Dave" <hermitd.REMOVE@.CAPS.AND.DOTS.hotmail.com> wrote in message
news:%23iXugImoEHA.1776@.TK2MSFTNGP14.phx.gbl...
> 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)
> "NOSPAM" <nospam@.xsagfgsagsafg.com> wrote in message
> news:OsCdnXI8-P3i_cncRVn-tA@.rogers.com...
> > 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
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)
"NOSPAM" <nospam@.xsagfgsagsafg.com> wrote in message
news:o-mdnbvzwqv89cncRVn-qQ@.rogers.com...
> 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.
>
> "Hermit Dave" <hermitd.REMOVE@.CAPS.AND.DOTS.hotmail.com> wrote in message
> news:%23iXugImoEHA.1776@.TK2MSFTNGP14.phx.gbl...
> > 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)
> > "NOSPAM" <nospam@.xsagfgsagsafg.com> wrote in message
> > news:OsCdnXI8-P3i_cncRVn-tA@.rogers.com...
> > > 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
> > >
Is this the book I should read?

http://www.amazon.com/exec/obidos/t...738524?v=glance

I am going to buy if this is the one... Thanks a lot.

"Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@.comcast.netNoSpamM> wrote in
message news:eFgtCKmoEHA.2140@.TK2MSFTNGP11.phx.gbl...
> 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!
> *************************************************
> "NOSPAM" <nospam@.xsagfgsagsafg.com> wrote in message
> news:OsCdnXI8-P3i_cncRVn-tA@.rogers.com...
> >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
Hi,

This is a fantastic read and it is free:
http://msdn.microsoft.com/architect...ns/html/Esp.asp

There are also many other patterns and practices that you will benefit from
reading. Understanding these will give you most of the design information
you will need for creating powerful applications. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight

"NOSPAM" <nospam@.xsagfgsagsafg.com> wrote in message
news:6d6dnSCkfaiQ6cncRVn-pg@.rogers.com...
> Is this the book I should read?
>
http://www.amazon.com/exec/obidos/t...738524?v=glance
> I am going to buy if this is the one... Thanks a lot.
>
>
> "Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@.comcast.netNoSpamM> wrote in
> message news:eFgtCKmoEHA.2140@.TK2MSFTNGP11.phx.gbl...
> > 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!
> > *************************************************
> > "NOSPAM" <nospam@.xsagfgsagsafg.com> wrote in message
> > news:OsCdnXI8-P3i_cncRVn-tA@.rogers.com...
> > >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
> > >
I use Rocky's CLSA framework in a large ASP.Net.
It works great. The book is one of the best "reads" out there.
There is a whole Users forum available for discussing how to implement CSLA.
http://groups.msn.com/CSLANET/messages.msnw

Petar Kozul has added some *amazing* extensions to the framework with his
ActiveObjects.
http://csla.kozul.info/
--
Joe Fallon

"NOSPAM" <nospam@.xsagfgsagsafg.com> wrote in message
news:6d6dnSCkfaiQ6cncRVn-pg@.rogers.com...
> Is this the book I should read?
> http://www.amazon.com/exec/obidos/t...738524?v=glance
> I am going to buy if this is the one... Thanks a lot.
>
>
> "Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@.comcast.netNoSpamM> wrote in
> message news:eFgtCKmoEHA.2140@.TK2MSFTNGP11.phx.gbl...
>> 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!
>> *************************************************
>> "NOSPAM" <nospam@.xsagfgsagsafg.com> wrote in message
>> news:OsCdnXI8-P3i_cncRVn-tA@.rogers.com...
>> >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
>>>>>
>>

0 comments:

Post a Comment