Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Casting Performance and Pattern Question

Reply
Thread Tools

Casting Performance and Pattern Question

 
 
Remco
Guest
Posts: n/a
 
      04-08-2004
Hi,

Let me try to simply explain my questions.

I've created a portal site with different types of users, e.g. Portal
Administrators and Normal Users.

One base class SessionUser (has a enum field UserType) and for each type of
user a inherited class like SessionMasterUser and SessionNormalUser.


Instantiating and keeping into a session:

case Normal user:

SessionUser user = new SessionNormalUser(loginName, pwd,
UserType.NormalUser)

All classes have different member variables and methods.

At the code behind pages I check for the Enum UserType and depending on that
I cast to the appropriate Type like ((SessionNormalUser)user).Email

What is better to do?

For each and everytime I need to access a member, property, or method from a
specific class (not the base class) by Casting?
or at places where it's needed more then once like following snippet.

SessionNormalUser normalUser = (SessionNormalUser)user

Question about that way: is there a performance penalty, since I understood
that there is only a new reference created to the object.

What's the cost of casting from a general to a more specific object?


Pattern Related Question(s)

In case of using the second option, which I prefer to make things easier to
read and understand, I don't want to create a null reference to all
different types of classes like:

SessionNormalUser normalUser = null;
SessionMasterUser masterUser = null;
etc...

I would like to create a kind of wrapper which is returning me the
appropriate information depending on the UserType enum.
This way should make things much more easier to maintain.

I know a bit about the design patterns but could you please give me a some
advice?

Thanks in Advance,

Remco



 
Reply With Quote
 
 
 
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      04-11-2004
> What's the cost of casting from a general to a more specific object?
not much expense here, casting is like putting a mask on over the face.

>SessionNormalUser normalUser = null;

I'm not sure why you think you need this line of code
--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/27cok
"Remco" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> Let me try to simply explain my questions.
>
> I've created a portal site with different types of users, e.g. Portal
> Administrators and Normal Users.
>
> One base class SessionUser (has a enum field UserType) and for each type
> of
> user a inherited class like SessionMasterUser and SessionNormalUser.
>
>
> Instantiating and keeping into a session:
>
> case Normal user:
>
> SessionUser user = new SessionNormalUser(loginName, pwd,
> UserType.NormalUser)
>
> All classes have different member variables and methods.
>
> At the code behind pages I check for the Enum UserType and depending on
> that
> I cast to the appropriate Type like ((SessionNormalUser)user).Email
>
> What is better to do?
>
> For each and everytime I need to access a member, property, or method from
> a
> specific class (not the base class) by Casting?
> or at places where it's needed more then once like following snippet.
>
> SessionNormalUser normalUser = (SessionNormalUser)user
>
> Question about that way: is there a performance penalty, since I
> understood
> that there is only a new reference created to the object.
>
> What's the cost of casting from a general to a more specific object?
>
>
> Pattern Related Question(s)
>
> In case of using the second option, which I prefer to make things easier
> to
> read and understand, I don't want to create a null reference to all
> different types of classes like:
>
> SessionNormalUser normalUser = null;
> SessionMasterUser masterUser = null;
> etc...
>
> I would like to create a kind of wrapper which is returning me the
> appropriate information depending on the UserType enum.
> This way should make things much more easier to maintain.
>
> I know a bit about the design patterns but could you please give me a some
> advice?
>
> Thanks in Advance,
>
> Remco
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ and design Pattern (Composite design Pattern ) Pallav singh C++ 0 01-22-2012 10:25 PM
Up casting and down casting Sosuke C++ 2 12-20-2009 03:24 PM
Problem with depracated casting method (down casting) Wally Barnes C++ 3 11-20-2008 05:33 AM
documents related to factory design pattern and Abstract foctory pattern. sunny C++ 1 12-07-2006 04:26 AM
Another question about inheritance (up-casting and down-casting) kevin Java 11 01-08-2005 07:11 PM



Advertisments