Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Inherting classes

Reply
Thread Tools

Inherting classes

 
 
ThatsIT.net.au
Guest
Posts: n/a
 
      09-07-2009
I have some inheritance in my classes
I have Administrator class and a Accounts class then inherit from the Staff
class, which in turn inherits from the Person class

I have a function that finds out if the user is a administrator or in
accounts and returns the correct object, I do not know what that will be so
I can not declare the object accounts or administrator, I have to declare it
as a Person or a Staff object like

dim oUser as Person = getUser(userId)
or
dim oUser as Staff = getUser(userId)

either will work of cause, but I wondering if their was a cost, and if you
should always take the base class or as high up in inheritance as you can.

Thanks

 
Reply With Quote
 
 
 
 
Nathan Sokalski
Guest
Posts: n/a
 
      09-07-2009
It is best to use the most specific class possible in your declaration,
because it means less converting will be involved, as well as leaving less
room for error. In your case, it sounds like this would be the Staff class.
However, for what you are doing I might suggest adding a property to the
Staff class (maybe named "Position" or "Department" or "Title"), and then in
the Administrator and Accounts classes, either set that property in the
constructor or override it so that it returns the desired value. Hopefully
this helps.
--
Nathan Sokalski
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.nathansokalski.com/

"ThatsIT.net.au" <me@work> wrote in message
news:(E-Mail Removed)...
>I have some inheritance in my classes
> I have Administrator class and a Accounts class then inherit from the
> Staff class, which in turn inherits from the Person class
>
> I have a function that finds out if the user is a administrator or in
> accounts and returns the correct object, I do not know what that will be
> so I can not declare the object accounts or administrator, I have to
> declare it as a Person or a Staff object like
>
> dim oUser as Person = getUser(userId)
> or
> dim oUser as Staff = getUser(userId)
>
> either will work of cause, but I wondering if their was a cost, and if you
> should always take the base class or as high up in inheritance as you can.
>
> Thanks



 
Reply With Quote
 
 
 
 
ThatsIT.net.au
Guest
Posts: n/a
 
      09-08-2009
The reason I ask is that when I set it as Person the base class, it does so
no problems, but when I set it as Staff more specific, it tells me strict
does not allow implicit conversion and I need to use CType.

"Nathan Sokalski" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> It is best to use the most specific class possible in your declaration,
> because it means less converting will be involved, as well as leaving less
> room for error. In your case, it sounds like this would be the Staff
> class. However, for what you are doing I might suggest adding a property
> to the Staff class (maybe named "Position" or "Department" or "Title"),
> and then in the Administrator and Accounts classes, either set that
> property in the constructor or override it so that it returns the desired
> value. Hopefully this helps.
> --
> Nathan Sokalski
> (E-Mail Removed)
> http://www.nathansokalski.com/
>
> "ThatsIT.net.au" <me@work> wrote in message
> news:(E-Mail Removed)...
>>I have some inheritance in my classes
>> I have Administrator class and a Accounts class then inherit from the
>> Staff class, which in turn inherits from the Person class
>>
>> I have a function that finds out if the user is a administrator or in
>> accounts and returns the correct object, I do not know what that will be
>> so I can not declare the object accounts or administrator, I have to
>> declare it as a Person or a Staff object like
>>
>> dim oUser as Person = getUser(userId)
>> or
>> dim oUser as Staff = getUser(userId)
>>
>> either will work of cause, but I wondering if their was a cost, and if
>> you should always take the base class or as high up in inheritance as you
>> can.
>>
>> Thanks

>
>


 
Reply With Quote
 
Nathan Sokalski
Guest
Posts: n/a
 
      09-08-2009
Could you post the signatures of all the classes?
--
Nathan Sokalski
(E-Mail Removed)
http://www.nathansokalski.com/

"ThatsIT.net.au" <me@work> wrote in message
news:(E-Mail Removed)...
> The reason I ask is that when I set it as Person the base class, it does
> so no problems, but when I set it as Staff more specific, it tells me
> strict does not allow implicit conversion and I need to use CType.
>
> "Nathan Sokalski" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> It is best to use the most specific class possible in your declaration,
>> because it means less converting will be involved, as well as leaving
>> less room for error. In your case, it sounds like this would be the Staff
>> class. However, for what you are doing I might suggest adding a property
>> to the Staff class (maybe named "Position" or "Department" or "Title"),
>> and then in the Administrator and Accounts classes, either set that
>> property in the constructor or override it so that it returns the desired
>> value. Hopefully this helps.
>> --
>> Nathan Sokalski
>> (E-Mail Removed)
>> http://www.nathansokalski.com/
>>
>> "ThatsIT.net.au" <me@work> wrote in message
>> news:(E-Mail Removed)...
>>>I have some inheritance in my classes
>>> I have Administrator class and a Accounts class then inherit from the
>>> Staff class, which in turn inherits from the Person class
>>>
>>> I have a function that finds out if the user is a administrator or in
>>> accounts and returns the correct object, I do not know what that will be
>>> so I can not declare the object accounts or administrator, I have to
>>> declare it as a Person or a Staff object like
>>>
>>> dim oUser as Person = getUser(userId)
>>> or
>>> dim oUser as Staff = getUser(userId)
>>>
>>> either will work of cause, but I wondering if their was a cost, and if
>>> you should always take the base class or as high up in inheritance as
>>> you can.
>>>
>>> Thanks

>>
>>

>



 
Reply With Quote
 
ThatsIT.net.au
Guest
Posts: n/a
 
      09-09-2009
well that was with a test class, I re-created then and its no longer asking
for cType, not sure why it was before.



"Nathan Sokalski" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Could you post the signatures of all the classes?
> --
> Nathan Sokalski
> (E-Mail Removed)
> http://www.nathansokalski.com/
>
> "ThatsIT.net.au" <me@work> wrote in message
> news:(E-Mail Removed)...
>> The reason I ask is that when I set it as Person the base class, it does
>> so no problems, but when I set it as Staff more specific, it tells me
>> strict does not allow implicit conversion and I need to use CType.
>>
>> "Nathan Sokalski" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> It is best to use the most specific class possible in your declaration,
>>> because it means less converting will be involved, as well as leaving
>>> less room for error. In your case, it sounds like this would be the
>>> Staff class. However, for what you are doing I might suggest adding a
>>> property to the Staff class (maybe named "Position" or "Department" or
>>> "Title"), and then in the Administrator and Accounts classes, either set
>>> that property in the constructor or override it so that it returns the
>>> desired value. Hopefully this helps.
>>> --
>>> Nathan Sokalski
>>> (E-Mail Removed)
>>> http://www.nathansokalski.com/
>>>
>>> "ThatsIT.net.au" <me@work> wrote in message
>>> news:(E-Mail Removed)...
>>>>I have some inheritance in my classes
>>>> I have Administrator class and a Accounts class then inherit from the
>>>> Staff class, which in turn inherits from the Person class
>>>>
>>>> I have a function that finds out if the user is a administrator or in
>>>> accounts and returns the correct object, I do not know what that will
>>>> be so I can not declare the object accounts or administrator, I have to
>>>> declare it as a Person or a Staff object like
>>>>
>>>> dim oUser as Person = getUser(userId)
>>>> or
>>>> dim oUser as Staff = getUser(userId)
>>>>
>>>> either will work of cause, but I wondering if their was a cost, and if
>>>> you should always take the base class or as high up in inheritance as
>>>> you can.
>>>>
>>>> Thanks
>>>
>>>

>>

>
>


 
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
GridView Inherting Chuck P ASP .Net Building Controls 6 07-12-2007 09:45 AM
Page inherting from .master - unexpected results =?Utf-8?B?QXJ0?= ASP .Net 0 05-26-2006 01:13 AM
Classes within classes David ASP .Net 2 07-22-2005 07:13 PM
Inherting from object. Or not. Frans Englich Python 7 01-28-2005 11:21 AM
How to access inner classes variables & methods from outer classes lonelyplanet999 Java 1 11-13-2003 01:54 PM



Advertisments