Smalltalk and Python

Rainer Deyke root at
Thu Dec 14 19:28:12 CET 2000

"Alex Martelli" <aleaxit at> wrote in message
news:91a4ht02e59 at
> I'd go further, and say that implementation-inheritance fans
> have never shown a compelling reason why any inheritance AT
> ALL is 'necessary' -- and we never will (I'll class myself among
> such fans:-), because it is *NOT* _necessary_.  Many complex
> LISP applications were programmed without actually using CLOS;
> C was used to program complex, successful applications, and has
> no inheritance at all; Visual Basic, up to version 6, did not
> allow implementation inheritance.  Whatever you can do by
> inheriting implementation, you can also do by encapsulating
> and delegating, and in some languages it's almost as easy
> (in Python, for example, a suitable __getattr__ method may
> let you 'transparently delegate' almost as conveniently as
> inheritance does).

While nothing is truly necessary in the absolute sense, there are cases
where implementation inheritance (and by extension multiple implementation
inheritance) is the only way to reuse another class, i.e. delegation is not
a viable substitute.

class A:
  def f(self): return self.g() + 5
  def g(self): return 5

class B(A):
  def g(self): return 23

my_object = B()
print my_object.f()

Rainer Deyke (root at
Shareware computer games           - 
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor

More information about the Python-list mailing list