Can you create an instance of a subclass with an existing instance of the base class?
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Fri Apr 28 16:56:15 EDT 2006
In <ldo-959EA0.19454927042006 at lust.ihug.co.nz>, Lawrence D'Oliveiro wrote:
> In article <444d4b92$0$7905$636a55ce at news.free.fr>,
> Bruno Desthuilliers <bdesth.quelquechose at free.quelquepart.fr> wrote:
>
>>Nope. I mean : they don't overuse OO, they overuse *classes*. AFAIK, OO
>>means *object* oriented - not class oriented.
>
> Oh great. Now we have someone redefining the concept of OO to evade the
> point I was making.
>
>>There are OO languages that don't even have a notion of class.
>
> Sounds like stuff I was doing in C (a non-OO language) years ago. Unless
> you want to count C as an OO language, I think you're going to have to
> retract this claim.
That sounds like stuff you do in a language that has objects but no
classes. As C has no objects I would not count it as an OO language. But
I count Io as an OO language::
#!/usr/bin/env io
Foo := Object clone
Foo value := 42
Foo setValue := method(newValue, self value = newValue; self)
Foo beep := method("beep" linePrint)
Foo asString := method("I'm a Foo. My value is " .. self value)
Bar := Foo clone
Bar asString := method("I'm a Bar and " .. super asString)
foo := Foo clone
foo beep
foo asString linePrint
bar := Bar clone setValue(23)
bar beep
bar asString linePrint
Output is:
beep
I'm a Foo. My value is 42
beep
I'm a Bar and I'm a Foo. My value is 23
That's OO IMHO. Clonable objects that know their "ancestors" so you can
build an object hierarchy. Missing attributes are looked up in the
"ancestors" and one can explicitly look up the inheritance tree with
``super``. There are no classes, just four objects. Convention in naming
and usage makes two of them something like templates or "classes" for new
objects but they are in no way special.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list