Re: Object inheritance question...
Re: Object inheritance question...
- Subject: Re: Object inheritance question...
- From: "Mark J. Reed" <email@hidden>
- Date: Tue, 27 Sep 2005 17:31:32 -0400
I would just like to add that even in cases where it conceptually
makes sense, inheritance (is-a) is often overused/abused, and
composition (has-a) is in general much easier to manage. Inheritance
is most useful when you have two classes that only differ in a few
details, and those details don't matter to most of the operations you
perform on the objects of those classes. The benefit is that those
operations which don't care about the minor details can be written
only once, rather than having their code duplicated in a nearly
identical versions, one per class.
It is unfortunate and confusing that both is-a and has-a occur as the
basic relationship in hierarchies which use similar terminology -
trees and parents and children and whatnot.
On 9/27/05, Brennan <email@hidden> wrote:
> On 26/9/05 at 17:01, Brendan Wilde <email@hidden> wrote:
>
> > I have a basic understanding of objects but i am having problems with a
> > concept can someone point
> > me in the right direction, refer to below... I want to pick which
> > object my new objects inherit from, at the moment i can only make
> > objects inherit from a single parent, but need to have a variable
> > amount of parents and then various children off each. For example 5
> > "street" objects each with various "house" objects.
> > So how do i make a "house" for my new street object that inherits all
> > of streets variables and methods etc?
> > An example would be great. Thanks Brendan...
>
> Something may be wrong here conceptually.
>
> Typically class B inherits class A's properties and methods because
> objects of class B are intended to resemble objects of class A in some
> way, and most usefully because there are classes C, D and E, which are
> also supposed to descend from class A.
>
> 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 choice of the word 'parent' was IMNSHO a mistake, because it confuses
> even those who think they know what they are talking about.
>
> So use the 'has a'/'is a' test if you are in doubt whether the 'parent'
> should be an ancestor or a container.
>
> Brennan
> --
> Brennan Young
>
> "The devotee believes that Krishna appears when his name is called. The guru understands that Krishna appears in the spaces between the name calling."
>
> -Swami Wassermann
> _______________________________________________
> 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
>
--
Mark J. Reed <email@hidden>
_______________________________________________
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