PEP 245: Python interfaces
Carlos Alberto Reis Ribeiro
cribeiro at mail.inet.com.br
Thu Mar 29 22:52:27 CEST 2001
At 15:00 29/03/01 +0200, Alex Martelli wrote:
>Fortunately, Python eschews such subtleties (which breed their own
>complications); adopting the explicit and very clear distinction that
>Java draws between 'extending' (a class) and 'implementing' (an interface)
>seems much preferable to me than either totally blurring (in the Python
>source) this crucial distinction, or adopting C++-inspired half-remedies
>to the is-a/vs/implementation confusion.
I entirely agree with you. One of the points that keeps bugging me is that
inheritance is not the only way to build OO systems. There are other
techniques, such as composition, the decorator pattern, proxies, that lead
to a more natural class hierarchy in several cases. By keeping interfaces
distinct from the class hierarchies, we are in fact making the support of
these approaches much simpler and straighforward.
For example, there is multiple inheritance. I know very few legitimate
cases where it is a good idea. Composition usually attains the same
results, but with less side effects and much better control over the
process. Interfaces are exceptionally well suited for this kind of construct.
More information about the Python-list