[Edu-sig] Getting ready for class...
Gregor Lingl
glingl at aon.at
Thu Mar 9 22:35:08 CET 2006
Andre Roberge schrieb:
> On 3/9/06, kirby urner <kirby.urner at gmail.com> wrote:
>
>>Here's what I'm starting with today:
>>
>>http://www.4dsolutions.net/ocn/python/zoo.py
>>
>>Note: inheriting from object at the top level, per André's suggestion.
>>
>>Kirby
>
>
> I like your examples. I imagine you are presenting them to the same
> group of students you mentioned before. One example that I've seen on
> comp.lang.python which I really like, especially because it has a
> second level of inheritance, is the following (original by John
> Gabriele, with comments modified slightly here):
>
Sorry Andre, but I really dislike this example. For me and in my lessons
inheritance is connected to an "isa" relation.
A Monkey isa Mammal etc.
This is violated here and i consider the confusion, which would be
caused by this example, would outweigh the benefits, if any ...
This doesn't work:
A parent "isa" grand_parent ? - no! A child "isa" parent ? - no! I
understand that the exmples goes about inheriting habits or opinions,
but I really think this shouldn't be done this way
Regards
Gregor
> #-----------------------------------------------------------------
> class Grand_parent( object ):
>
> def speak( self ):
> print 'Grand_parent.speak()'
> self.advise()
>
> def advise( self ):
> print 'Grand_parent.advise()'
> self.critique()
>
> def critique( self ):
> print 'Grand_parent.critique()'
>
> #-----------------------------------------------------------------
> class Parent( Grand_parent ):
>
> def speak( self ):
> print '\tParent.speak()'
> self.advise()
>
> def advise( self ):
> print '\tParent.advise()'
> self.critique()
>
> # The Parent inherits his criticism method from his/her own parent
>
> #-----------------------------------------------------------------
> class Child( Parent ):
>
> def speak( self ):
> print '\t\tChild.speak()'
> self.advise()
>
> # Currently, the Child has no really useful advice to give. The
> child will just
> # parrot what he/she hears the parent say.
>
> def critique( self ):
> print '\t\tChild.critique()'
>
> #-----------------------------------------------------------------
> print 'speak() calls advise(), then advise() calls critique().'
> print
>
> people = [ Grand_parent(), Parent(), Child() ]
> for person in people:
> person.speak()
> print
>
> ====================
> The output is:
>
> speak() calls advise(), then advise() calls critique().
>
> Grand_parent.speak()
> Grand_parent.advise()
> Grand_parent.critique()
>
> Parent.speak()
> Parent.advise()
> Grand_parent.critique()
>
> Child.speak()
> Parent.advise()
> Child.critique()
>
> André
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>
>
--
Gregor Lingl
Reisnerstrasse 3/19
A-1030 Wien
Telefon: +43 1 713 33 98
Mobil: +43 664 140 35 27
Website: python4kids.net
More information about the Edu-sig
mailing list