Carrying Objects

T

tshad

I have a User object that has all the information on the object (firstName,
LastName, email, userName, password, address, gender, dob etc).

I want to only carry in a session variable the logon information (firstName,
LastName, email, userName, password).

Is it best to just carry all the information or create a different object
with just a subset of the information?

I am concerned with efficiency and speed here. If I am carrying a lot of
large objects, I assume that would eat more memory and slow down processing.

Thanks,

Tom
 
L

Lucas Tam

I have a User object that has all the information on the object
(firstName, LastName, email, userName, password, address, gender, dob
etc).

I want to only carry in a session variable the logon information
(firstName, LastName, email, userName, password).

Is it best to just carry all the information or create a different
object with just a subset of the information?

I am concerned with efficiency and speed here. If I am carrying a lot
of large objects, I assume that would eat more memory and slow down
processing.

Considering this object is only storing text information - it's probably
not going to impact your application too much.

But you might want to extend IIdentity instead - this object is attached
to each authenticated session when it gets authentication and it would
be a good place to place additional user properties.

http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/cpref/html/frlrfsystemsecurityprincipaliidentityclasstopic.asp
 
K

Karl Seguin

One solution is to use composition, where one object is composed of another.

pulblic class UserData
{
private string _firstName;
private string _userName;
...
public string FirstName{
get { return _firstName; }
set { _firstName = value;
}
public string UserName{
get { return _userName; }
set { _userName= value;
}
}

public class User
{
private UserData _userData;
private DateTime _dob;
...
public DateTime Dob{
get { return _dob; }
set { _dob = value; }
}
//User is composed of userData, but exposes the properties as though they
are part of it (no one exteranlly needs to know that we are using
composition)
public string FirstName{
get { return userData.FirstName; }
set { _userData.FirstName = value;
}
public string UserName{
get { return userData.UserName; }
set { userData.UserName= value;
}

//get the core data to store in ur session
public UserData CoreData{
get { return _userData;}
}

//create a new user based on the core-data
public User(UserData coreData)
{
_userData = coreData;
}
}



you can then do stuff like:

User user = User.GetUser(1);
Session["CurrentUser"] = user.CodeData;



and then re-create ur user via:


User user =new User((UserData)Session["CurrentUser"]);


Karl
 
T

tshad

Lucas Tam said:
Considering this object is only storing text information - it's probably
not going to impact your application too much.

But you might want to extend IIdentity instead - this object is attached
to each authenticated session when it gets authentication and it would
be a good place to place additional user properties.

That is probably true, but I haven't worked with that yet and is my next
step, but I need to get this working simply first and then add that later.
May be a little more work, but am under a time crunch here.

Thanks,

Tom
 

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,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top