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 1908
> 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: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |