Re: Business Objects and Session Variables

From: Cowboy \(Gregory A. Beamer\) (NoSpamMgbworld_at_comcast.netNoSpamM)
Date: 02/03/04


Date: Tue, 3 Feb 2004 08:05:26 -0600

General:
--------
Best bet is to look at www.dofactory.com, as there are a lot of
implementations of patterns here. Microsoft also has some great (free) books
on architecture using patterns at http://msdn.microsoft.com/architecture -
look at Patterns and Practices.

A factory method (using a factory pattern) is one that returns an object to
you based on certain criteria. When you implement a factory pattern, you
have the option of later adding cache capabilities. This is more flexible
than simply creating a user object. In addition, you can abstract the
factory method to allow you to return slightly different objects derived
from the same base class (for example, a visitor object, an employee object
and an administrator object -- each with different levels of access, but
each derived from a base user object).

Specific:
--------
The main point I was making with the factory method, is you can then
determine whether you need to store the object in session, or reconstitute
it from the database on each hit.

public User GetUserObject(long userID)
{
}

public User GetUserObject(string sessionID)
{
}

With these two methods, you can either pull from session or rebuild from the
database. In your code, the call will still be something like:

string SessionID = Session.ID.ToString();
User user = GetUserObject(sessionID);

Initially, the internals for the GetUserObject() method are pulling from
Session, like:

public User GetUserObject(string sessionID)
{
    return (User) Session["User"];
}

But, you could flip to rebuilding each time, if it works better, without
refactoring all of your calls, which would be spread throughout your ASP.NET
application.

-- 
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
**********************************************************************
Think Outside the Box!
**********************************************************************
"Dave Wurtz" <dave_!!no_spam!!wurtz@asdsoftware.com> wrote in message
news:401e9c9c@news.splitrock.net...
> Can you expand on this:
>
> > If you want to have the greatest flexibility, make a factory method that
> > returns the user object from userID (or overload, from sessionID). You
can
> > then feed the Session User Object or the database user object without a
> > major re-architecture.
>
> What do you mean by 'factory method'?
>
> Thank you!
> Dave
>
> "Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@comcast.netNoSpamM> wrote in
> message news:OSy0S0a6DHA.2628@TK2MSFTNGP10.phx.gbl...
> > Because of the nature of the web (long periods of inactivity) and the
fact
> > that a user object is generally low perf hit to fill (via database
> > retrieval), I do not see as great a benefit to dropping objects into
> > session, but I am not adverse to it either.
> >
> > The biggest question, for your app, is which is going to cause more
> > problems:
> > 1. A bunch of unused objects in memory for extended periods of time (20
> > minutes after last hit by default)
> > 2. Hitting the database to get user info when a user requests a page
> >
> > In some apps, the memory usage will kill scalability. For others, the
> > minimal lag to the RDBMS is the killer. In most, it does not matter one
> way
> > or the other.
> >
> > If you want to have the greatest flexibility, make a factory method that
> > returns the user object from userID (or overload, from sessionID). You
can
> > then feed the Session User Object or the database user object without a
> > major re-architecture.
> >
> > -- 
> > Gregory A. Beamer
> > MVP; MCP: +I, SE, SD, DBA
> >
> > **********************************************************************
> > Think Outside the Box!
> > **********************************************************************
> > "Dave Wurtz" <dave_!!no_spam!!wurtz@asdsoftware.com> wrote in message
> > news:401e775d$1@news.splitrock.net...
> > > All,
> > >
> > > I'm new to ASP development and I have a basic design question:
> > >
> > > Is it ok to store business objects to session variables or is there a
> > better
> > > way to keep object information?
> > >
> > > For example, if a user logs onto the website, a user object is created
> > that
> > > stores their full name, email address, street address, phone, etc.
This
> > > object also has methods to do 'other' things such as validations,
> > counters,
> > > etc.  When the user logs in, the object is instantiated.  Is it ok to
> keep
> > > this object for the life of the session?  If some items are always
> needed
> > > (for example maybe the full name is on the header of every page), it
is
> > very
> > > convenient just to call a property off of the user object.
> > >
> > > I've also seen some examples where the primary key of the object is
> stored
> > > in the session variable, and the object is rebuilt all of the time.
> Which
> > > way is better?
> > >
> > > Storing the user object for the life of the session is definitely more
> > > convenient for the programmer, but is it going to kill my performance?
> On
> > > the other hand, recreating the user object each time would potentially
> > have
> > > to requery the database to retrieve information - is this going to
kill
> my
> > > performance?
> > >
> > > Any help on this would be very much appreciated!
> > >
> > > Thanks.
> > >
> > > Dave Wurtz
> > > Advanced Software Designs
> > >
> > >
> >
> >
>
>


Relevant Pages

  • Re: how to delete a file that is related to the session object
    ... i have a static object which is created each time the session start: ... this user object is reffered to in my code this way: ... if the application's user closes the window, ... session ends, the garbage collector doesn't always work at that instance. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Business Objects and Session Variables
    ... > returns the user object from userID (or overload, ... > session, but I am not adverse to it either. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Newbie Question: Password protect a webpage
    ... > On the gateway page, you place a javascript which asks for the password, ... login credentials serverside, and then store the user id (or better yet, ... User object) in the session: ...
    (comp.lang.java)
  • Re: Business Objects and Session Variables
    ... that a user object is generally low perf hit to fill (via database ... session, but I am not adverse to it either. ... Hitting the database to get user info when a user requests a page ... returns the user object from userID ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Is that a good design?
    ... I do not see the sense in the User object as it is, ... public string FirstName; ... Both are acceptable patterns. ... Class Factory pattern to help in isolate our code. ...
    (microsoft.public.dotnet.framework)