Persisting business layer objects | | |
I am new to 3-tiered design and am in the process of designing an
application that will work with ASP.NET as well as Windows Forms (and
possibly with a PDA of some sort down the road). My question is about
the statefulness of business objects. In some of the examples that
I've seen of 3-tiered systems using ASP.NET, the business objects are
recreated every time they are accessed. They are not kept in the
Session variable for use next time the GUI needs them. This seems like
it could come with considerable performance penalties, but would be
simpler to maintain. What are the arguments for and against trying to
maintain the business layer objects between postbacks? Do non web
based applications (like Win Forms) usually keep the business objects
in memory when not in use?
Thanks,
Dave | | | | re: Persisting business layer objects
Hi Dave,
Let's start with your last question:
[color=blue]
> Do non web
> based applications (like Win Forms) usually keep the business objects
> in memory when not in use?[/color]
A desktop application has a constant and unchanging memory space to work
with. So, obviously, the answer is "yes."
A web application is made up of many separate pages that are served up via
HTTP to client browsers. HTTP is a stateless protocol, which means that each
Request and Response happens "in a vacuum" (so to speak). The server forgets
about the last Request as soon as it has fulfilled it. There is no
persistence of memory, other than the "containers" that ASP.Net maintains,
including Application, Session, etc. These exist for that reason
(statelessness).
Now, as to your first question:
[color=blue]
> What are the arguments for and against trying to
> maintain the business layer objects between postbacks?[/color]
There is no "one size fits all" rule for this. It depends upon your
requirements, and how, when, and where these objects are being used. If, for
example, you have a class which provides the data for menus that are used in
all pages, you would most likely store that data in the Application Cache.
If, however, a business class is only used on a single page, it might be
best to instantiate it with each new Request for that page. On the other
hand, if the class is used on many pages by a single user, it might be best
to cache it in Session State.
The bottom line is, it's a trade-off. Caching objects costs you RAM on the
server. Not caching them costs you processing. You need to determine, based
upon the individual usage of these classes, whether the trade-off will be
less expensive overall.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"headware" <headware@aol.com> wrote in message
news:e3f4b0ae.0406152119.4a87e4f3@posting.google.c om...[color=blue]
> I am new to 3-tiered design and am in the process of designing an
> application that will work with ASP.NET as well as Windows Forms (and
> possibly with a PDA of some sort down the road). My question is about
> the statefulness of business objects. In some of the examples that
> I've seen of 3-tiered systems using ASP.NET, the business objects are
> recreated every time they are accessed. They are not kept in the
> Session variable for use next time the GUI needs them. This seems like
> it could come with considerable performance penalties, but would be
> simpler to maintain. What are the arguments for and against trying to
> maintain the business layer objects between postbacks? Do non web
> based applications (like Win Forms) usually keep the business objects
> in memory when not in use?
>
> Thanks,
> Dave[/color] | | | | re: Persisting business layer objects
Kevin,
I appreciate the reply. I guess we'll have to be careful to make the
business layer objects work independently of whether they are being
stored in memory (as they would be in Win Forms) or whether they are
created every time they are accessed (as they might be in Web Forms).
Thanks,
Dave
"Kevin Spencer" <kspencer@takempis.com> wrote in message news:<u07g4h6UEHA.1888@TK2MSFTNGP11.phx.gbl>...[color=blue]
> Hi Dave,
>
> Let's start with your last question:
>[color=green]
> > Do non web
> > based applications (like Win Forms) usually keep the business objects
> > in memory when not in use?[/color]
>
> A desktop application has a constant and unchanging memory space to work
> with. So, obviously, the answer is "yes."
>
> A web application is made up of many separate pages that are served up via
> HTTP to client browsers. HTTP is a stateless protocol, which means that each
> Request and Response happens "in a vacuum" (so to speak). The server forgets
> about the last Request as soon as it has fulfilled it. There is no
> persistence of memory, other than the "containers" that ASP.Net maintains,
> including Application, Session, etc. These exist for that reason
> (statelessness).
>
> Now, as to your first question:
>[color=green]
> > What are the arguments for and against trying to
> > maintain the business layer objects between postbacks?[/color]
>
> There is no "one size fits all" rule for this. It depends upon your
> requirements, and how, when, and where these objects are being used. If, for
> example, you have a class which provides the data for menus that are used in
> all pages, you would most likely store that data in the Application Cache.
> If, however, a business class is only used on a single page, it might be
> best to instantiate it with each new Request for that page. On the other
> hand, if the class is used on many pages by a single user, it might be best
> to cache it in Session State.
>
> The bottom line is, it's a trade-off. Caching objects costs you RAM on the
> server. Not caching them costs you processing. You need to determine, based
> upon the individual usage of these classes, whether the trade-off will be
> less expensive overall.
>
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> Big things are made up
> of lots of little things.
>
> "headware" <headware@aol.com> wrote in message
> news:e3f4b0ae.0406152119.4a87e4f3@posting.google.c om...[color=green]
> > I am new to 3-tiered design and am in the process of designing an
> > application that will work with ASP.NET as well as Windows Forms (and
> > possibly with a PDA of some sort down the road). My question is about
> > the statefulness of business objects. In some of the examples that
> > I've seen of 3-tiered systems using ASP.NET, the business objects are
> > recreated every time they are accessed. They are not kept in the
> > Session variable for use next time the GUI needs them. This seems like
> > it could come with considerable performance penalties, but would be
> > simpler to maintain. What are the arguments for and against trying to
> > maintain the business layer objects between postbacks? Do non web
> > based applications (like Win Forms) usually keep the business objects
> > in memory when not in use?
> >
> > Thanks,
> > Dave[/color][/color] |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,327 network members.
|