question about globals vars...

Will Stuyvesant hwlgw at hotmail.com
Fri Aug 2 16:43:38 EDT 2002


Just posted a reply to your questions about globals with an example of
problems with OO programming.
A better example is this:
Suppose class S has methods push(x), pop() and multipop(n), with
obvious meanings.
Now suppose you want to code class Sn and inherit from class S and
implement a numberOfItems attribute.  If multipop(n) calls pop() n
times you have to override pop() so it will update numberOfItems
correctly.  But if multipop(n) does not call pop() you would have to
override multipop().  To decide what to do you have to look at the
source code of class S.  In an ideal situation the documentation of S
tells you all you need, but this is rarely the case and in the last
example it will probably not be documented if multipop calls pop.

'''
A man who carries a cat by its tail learns something he can learn in
no other way.
'''



More information about the Python-list mailing list