Object inheritance question, pt 2...
Object inheritance question, pt 2...
- Subject: Object inheritance question, pt 2...
- From: Brendan Wilde <email@hidden>
- Date: Wed, 28 Sep 2005 17:21:24 +1000
I did say i had a "basic understanding" of objects. :)
I would like to explain what I am doing and if I am totally off track,
maybe someone could explain the "correct" way to do it.
I am reading a tabbed text doc which will be used to make quark or
indesign
pages. It will list info about the document, the pages, groups of
elements on a page
and then the sub elements of each group. So I am placing all the info
from the text
document into objects so it can be randomly accessed when ever it is
needed.
What I am doing is making a "doc" object.
This "doc" object will then have a subclass for "page" objects that
inherit the details of the document
(which to start with will probably be mainly the filename)
then the "pages" will have a sub class of the elements on the page.
So if i need info on any item in the document, it's object will know
what page it's from
and what document.
I guess this isn't a "is a" relationship, more like a "has a", so is
this wrong?
If you like I could say that this element "is a(n)" element of this
page, which "is a" page of this document.
But I couldn't say that this element "is a" page, and this page, "is a"
document.
This will work for my purposes but if this is the wrong way of looking
at it then how should
I be going about solving this problem (and others in the future.)
Thanks
Brendan
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
_______________________________________________
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