Re: Object inheritance question...
Re: Object inheritance question...
- Subject: Re: Object inheritance question...
- From: Matt Neuburg <email@hidden>
- Date: Tue, 27 Sep 2005 16:41:05 -0700
- Thread-topic: Object inheritance question...
On Tue, 27 Sep 2005 15:25:53 +0200, Brennan <email@hidden> said:
>There is an important difference, often mentioned when describing OOP,
>between an "is a" and a "has a" relationship.
>
>A cat *is a* mammal, a dog *is a* mammal, so they both inherit milk glands
>from the mammal class. (Mammal in turn descends from the Vertebrate class
>etc.)
>
>A street "has a" house, it does not make sense to 'go for a walk down the
>house', so it's not conceptually right for the house class to inherit from
>the street class. In this case we would say that the street *contains*
>some houses. A house is an *element* of a street, not a special kind of
>street.
>
>House (like garage, shed and skyscraper) might more usefully descend from
>the 'building' class.
>
>We might also imagine a 'one way street' class, or a cul-de-sac (or
>whatever that's called in US English) descending from the 'street' class.
>
>The problem is that AppleScript uses the ambiguous word 'parent' for
>inheritance, which is often (conceptually) used to denote 'container' as
>well as 'ancestor'.
The real problem is that AppleScript tries to pretend it's doing "is-a" when
in fact it's doing "has-a". Every script object has a parent property and it
uses this as a delegate when you refer to a top-level entity. The automatic
delegation messaging is cute but there isn't really any OOP going on here at
all because there are not really classes (despite the use of the term
"class" as a property name).
Hamish Sanderson has given some nice examples, along this line:
script s
property parent : {1, 2, 3}
end script
class of s -- script
count s -- 3
item 1 of s -- 1
So s is able to delegate "count" and "item" to its parent; but s is in no
sense itself a list. It simply has a list that it does some delegating with.
Because of this I almost changed the term "inheritance chain" to "delegation
chain" in the new edition of my book, but in the end I decided it wasn't
worth it. m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide
<http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden