Inherting classes

Discussion in 'ASP .Net' started by ThatsIT.net.au, Sep 7, 2009.

  1. 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
    ThatsIT.net.au, Sep 7, 2009
    #1
    1. Advertising

  2. 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.nathansokalski.com/

    "ThatsIT.net.au" <me@work> wrote in message
    news:...
    >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
    Nathan Sokalski, Sep 7, 2009
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:...
    > 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.nathansokalski.com/
    >
    > "ThatsIT.net.au" <me@work> wrote in message
    > news:...
    >>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

    >
    >
    ThatsIT.net.au, Sep 8, 2009
    #3
  4. Could you post the signatures of all the classes?
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "ThatsIT.net.au" <me@work> wrote in message
    news:...
    > 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" <> wrote in message
    > news:...
    >> 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.nathansokalski.com/
    >>
    >> "ThatsIT.net.au" <me@work> wrote in message
    >> news:...
    >>>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

    >>
    >>

    >
    Nathan Sokalski, Sep 8, 2009
    #4
  5. 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" <> wrote in message
    news:%...
    > Could you post the signatures of all the classes?
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    > "ThatsIT.net.au" <me@work> wrote in message
    > news:...
    >> 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" <> wrote in message
    >> news:...
    >>> 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.nathansokalski.com/
    >>>
    >>> "ThatsIT.net.au" <me@work> wrote in message
    >>> news:...
    >>>>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
    >>>
    >>>

    >>

    >
    >
    ThatsIT.net.au, Sep 9, 2009
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David

    Classes within classes

    David, Jul 21, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    4,927
    David
    Jul 22, 2005
  2. lonelyplanet999
    Replies:
    1
    Views:
    2,201
    VisionSet
    Nov 13, 2003
  3. =?Utf-8?B?QXJ0?=

    Page inherting from .master - unexpected results

    =?Utf-8?B?QXJ0?=, May 26, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    348
    =?Utf-8?B?QXJ0?=
    May 26, 2006
  4. Frans Englich

    Inherting from object. Or not.

    Frans Englich, Jan 26, 2005, in forum: Python
    Replies:
    7
    Views:
    357
    Nick Coghlan
    Jan 28, 2005
  5. Chuck P

    GridView Inherting

    Chuck P, Jun 25, 2007, in forum: ASP .Net Building Controls
    Replies:
    6
    Views:
    751
    Walter Wang [MSFT]
    Jul 12, 2007
Loading...

Share This Page