[ZDP] BackTalk to Document The Zope Book (2.6 Edition)/Acquisition

webmaster at zope.org webmaster at zope.org
Mon Jan 12 23:08:20 EST 2004


A comment to the paragraph below was recently added via http://zope.org/Documentation/Books/ZopeBook/2_6Edition/Acquisition.stx#2-1

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

    In a typical object-oriented language, there are rules to the way
    a *subclass* inherits behavior from its *superclasses*.  For
    example, in Python (a *multiple-inheritance* language), a class
    may have more than one superclass, and rules are used to determine
    which of a class' superclasses is used to define behavior in any
    given circumstance.  We'll define a few Python classes here to
    demonstrate.  You don't really need to know Python inside and out
    to understand these examples.  Just know that a 'class' statement
    defines a class and a 'def' statement inside of a class statement
    defines a method.  A class statement followed by one or more words
    inside (Parenthesis) causes that class to *inherit* behavior from
    the classes named in the parenthesis.::

      class SuperA:
          def amethod(self):
              print "I am the 'amethod' method of the SuperA class"

          def anothermethod(self):
              print "I am the 'anothermethod' method of the SuperA class"

      class SuperB:
          def amethod(self):
              print "I am the 'amethod' method of the SuperB class"

          def anothermethod(self):
              print "I am the 'anothermethod' method of the SuperB class"

          def athirdmethod(self):
              print "I am the 'anothermethod' method of the SuperB class"

      class Sub(SuperA, SuperB):
          def amethod(self):
              print "I am the 'amethod' method of the Sub class"

      % Anonymous User - Jan. 12, 2004 11:08 pm:
       In the SuperB class, athirdmethod() should probably print that it is the 'athirdmethod' method, rather than
       the 'anothermethod' method (which it isn't). It might confuse people who are new or (like me) sleepy.



More information about the ZDP mailing list