Python 1.6 The balanced language
Neel Krishnaswami
neelk at brick.cswv.com
Sun Sep 3 10:11:20 EDT 2000
Alex Martelli <aleaxit at yahoo.com> wrote:
>
> "subtyping exists" is another contentious issue, of course; if I
> removed "extends" from Java, requiring all polymorphous use to
> go through "interface" and "implement" (as, e.g., Coad has suggested
> as best design practice), would I "totally lose OO-ness"?
No, because you still have subtyping. You've taken away inheritance,
but that's not the same thing (see Sather for a rather graphic
illustration of the difference).
> Are languages based on 'prototype objects' (with no classes at all)
> "not OO"? Pah...
You still have types as a semantic concept in Self and Cecil, though.
A type object is one which other objects name as a delegate; grab all
the objects that delegate to it and you have all its direct instances.
The fact that an object's type can change over its lifetime isn't a
disqualification. Note that this isn't that foreign to Python, either:
you can change an object's class by setting the __class__ field, and
you can change the inheritance graph by setting __bases__.
>>> class Foo: pass
...
>>> class Bar: pass
...
>>> x = Foo()
>>> isinstance(x, Foo)
1
>>> isinstance(x, Bar)
0
>>> x.__class__ = Bar
>>> isinstance(x, Foo)
0
>>> isinstance(x, Bar)
1
>>> Bar.__bases__ = (Foo,)
>>> isinstance(x, Foo)
1
>>> isinstance(x, Bar)
1
Neel
More information about the Python-list
mailing list