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 2 1899
> 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" <re*****@hotmail.com> wrote in message
news:eA**************@TK2MSFTNGP11.phx.gbl... 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
> 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" <re*****@hotmail.com> wrote in message
news:eA**************@TK2MSFTNGP11.phx.gbl... 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kevin C |
last post by:
Quick Question:
StringBuilder is obviously more efficient dealing with string concatenations
than the old '+=' method... however, in dealing with relatively large string
concatenations (ie,...
|
by: Jacob Jensen |
last post by:
This question has probably been asked a million time, but here it comes
again. I want to learn the difference between the three type cast operators:
static_cast, reinterpret_cast, dynamic_cast. A...
|
by: Kurt |
last post by:
i just can't figure out why something im doing is not
working correctly....
public interface IInterface
{
int someProperty
{
get;
set;
}
|
by: Kurt Lange |
last post by:
no... the array is created dynamically.
and no... that defeats the purpose of what im trying
todo..
encapsulate all initializing of variables in base
class...
derive from it... by deriving...
|
by: RepStat |
last post by:
I've read that it is best not to use exceptions willy-nilly for stupid purposes as they can be a major performance hit if they are thrown. But is it a performance hit to use a try..catch..finally...
|
by: Marco |
last post by:
I need to get a iterator from any generic collection.
public class .... GetIterator(Object collection)
{
.....
}
|
by: Remco |
last post by:
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...
|
by: Nacho |
last post by:
Hi,
I'm designing a new database and I have a doubt in which surely you
can help me.
I'm storing in this database historical data of some measurements and
the system in constantly growing, new...
|
by: Ken Fine |
last post by:
This is a basic question. What is the difference between casting and using
the Convert.ToXXX methods, from the standpoint of the compiler, in terms of
performance, and in other ways? e.g.
...
|
by: =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?= |
last post by:
I'm doing my c# more and more like i used to code c++, meaning i'm casting
more often than creating an instance of objects.
like :
protected void gvOrderDetailsRowDataBound(object sender,...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |