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 SessionMasterUs er and SessionNormalUs er.
Instantiating and keeping into a session:
case Normal user:
SessionUser user = new SessionNormalUs er(loginName, pwd,
UserType.Normal User)
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 ((SessionNormal User)user).Emai l
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.
SessionNormalUs er normalUser = (SessionNormalU ser)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:
SessionNormalUs er normalUser = null;
SessionMasterUs er 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 1969
> 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. SessionNormalU ser 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*****@hotmai l.com> wrote in message
news:eA******** ******@TK2MSFTN GP11.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 SessionMasterUs er and SessionNormalUs er.
Instantiating and keeping into a session:
case Normal user:
SessionUser user = new SessionNormalUs er(loginName, pwd, UserType.Normal User)
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 ((SessionNormal User)user).Emai l
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.
SessionNormalUs er normalUser = (SessionNormalU ser)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:
SessionNormalUs er normalUser = null; SessionMasterUs er 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. SessionNormalU ser 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*****@hotmai l.com> wrote in message
news:eA******** ******@TK2MSFTN GP11.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 SessionMasterUs er and SessionNormalUs er.
Instantiating and keeping into a session:
case Normal user:
SessionUser user = new SessionNormalUs er(loginName, pwd, UserType.Normal User)
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 ((SessionNormal User)user).Emai l
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.
SessionNormalUs er normalUser = (SessionNormalU ser)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:
SessionNormalUs er normalUser = null; SessionMasterUs er 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, 20-30k), what are the performance differences (if any
with something as trivial as this) between initializing a new instance of
StringBuilder with a specified capacity vs. initializing a new instance
without... (the final length is not fixed)
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 good way to do this is by
example. So I will give an example and please tell me what you think:
I have a base
class A
with a virtual destructor, and a
class B
that is it inherits publicly from A and defines som extra stuff.
|
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 from base class, and
casting, derived classes would already have their
variables initialiezed(cause they have already been
initialized in the base class) ....
|
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 block, just in case there might be an exception? i.e. is it ok performance-wise to pepper pieces of code with try..catch..finally blocks that must be robust, in order that cleanup can be done correctly should there be an exception?
| |
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 field UserType) and for each type of
user a inherited class like SessionMasterUser and SessionNormalUser.
|
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 measurements are added every
day.
So, I have to set some extra columns in advance, so space is available
whenever is needed and the client doesn't have to modify the structure
in SQL server.
|
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.
this.ContentID = (int)ci.Conid;
vs.
this.ContentID = Convert.ToInt32(ci.Conid);
I tend to use the latter form because it seems more descriptive to me, but
it would be good to know what's best practice. I'm guessing those methods
|
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,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
switch (((Sale)e.Row.DataItem).SzPN)
{
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |