Inheritance/Late Private Binding

Discussion in 'Python' started by Jeremy Moles, Jul 7, 2005.

  1. Jeremy Moles

    Jeremy Moles Guest

    class BaseClass:
    def __init__(self):
    self.__data = None

    def getMember(self):
    return self.__data

    class GoodSubClass(BaseClass):
    def __init__(self):
    BaseClass.__init__(self)

    class BadSubClass(BaseClass):
    def __init__(self):
    self.__x = None

    gsc = GoodSubClass()
    print dir(gsc)
    gsc.getMember()

    bsc = BadSubClass()
    print dir(bsc)
    bsc.getMember()

    ------------------------------------------------

    Forgive me if this topic has been brought up before, but I was curious
    as to why I was getting this behavior and was hoping someone
    knowledgeable could explain. :)

    I "feel" like even without the explicit call to a simple base ctor(),
    mangling should still happen correctly. This doesnt, however, seem to be
    the case...

    Of note: simply doing a 'pass' in BadSubClass seems to be sufficient as
    well; so, it has something to do with defining a ctor() in the child and
    not explicitly invoking the parent's ctor.
    Jeremy Moles, Jul 7, 2005
    #1
    1. Advertising

  2. Jeremy Moles wrote:

    > Forgive me if this topic has been brought up before, but I was curious
    > as to why I was getting this behavior and was hoping someone
    > knowledgeable could explain. :)


    What behavior?

    > I "feel" like even without the explicit call to a simple base ctor(),
    > mangling should still happen correctly. This doesnt, however, seem to be
    > the case...


    How is mangling happening incorrectly?

    Functions in base classes that are overridden by subclasses aren't
    called implicitly.

    Also, I think using the term "ctor()" is confusing since you don't seem
    to have anything callable named ctor. As for the constructor, just call
    it __init__, it will avoid confusion with __new__.
    --
    Michael Hoffman
    Michael Hoffman, Jul 7, 2005
    #2
    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. ThunderMusic

    Plugins and Late Binding

    ThunderMusic, Jan 27, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    853
    Patrice
    Apr 12, 2005
  2. maxw_cc
    Replies:
    1
    Views:
    3,138
    Martijn van Steenbergen
    Dec 21, 2003
  3. qazmlp
    Replies:
    19
    Views:
    789
    Daniel T.
    Feb 4, 2004
  4. Replies:
    2
    Views:
    857
    Kevin Grover
    Oct 20, 2006
  5. karthikbalaguru
    Replies:
    9
    Views:
    1,036
Loading...

Share This Page