• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Object inheritance question...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Object inheritance question...


  • Subject: Re: Object inheritance question...
  • From: Simon Forster <email@hidden>
  • Date: Mon, 26 Sep 2005 08:55:05 +0100


On 26 Sep 2005, at 08:01, Brendan Wilde wrote:

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.

Hi Brendan

I've taken your example and modified it a bit (see below sig). Each script object is wrapped in a constructor function but otherwise it's pretty much your code.

Hope it makes sense.

All the best

Simon Forster
_____________________________________________________
 LDML Ltd, 62 Pall Mall, London, SW1Y 5HZ, UK
 Tel: +44 (0)70 9230 5244   Fax: +44 (0)70 9230 5247
_____________________________________________________


on makeStreet(theStreetName)
script street
property streetName : theStreetName
on displayName()
display dialog "I am \"" & streetName & "\" and I want a house too!"
end displayName
on setName(x)
set streetName to x
end setName
on getName()
return streetName
end getName
end script
end makeStreet


on makeHouse(parentStreet, theHouseNumber)
script house
property parent : parentStreet
property houseNumber : theHouseNumber
on displayName()
display dialog "I am " & houseNumber & ", " & getName() & "."
end displayName
end script
end makeHouse


set listStreet to {}
set end of listStreet to makeStreet("High Street")
set end of listStreet to makeStreet("Low Street")

--tell item 1 of listStreet to displayName() -->'I am "High Street" and I want a house too!'
--tell item 2 of listStreet to displayName() -->'I am "Low Street" and I want a house too!'


set listHouse to {}
set end of listHouse to makeHouse(item 1 of listStreet, "1")
set end of listHouse to makeHouse(item 2 of listStreet, "2")
set end of listHouse to makeHouse(item 2 of listStreet, "3")
set end of listHouse to makeHouse(item 1 of listStreet, "4")
tell item 1 of listHouse to displayName() -->'I am 1, High Street'
tell item 2 of listHouse to displayName() -->'I am 2, Low Street'
tell item 3 of listHouse to displayName() -->'I am 3, Low Street'
tell item 4 of listHouse to displayName() -->'I am 4, High Street'




_______________________________________________ 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
References: 
 >Object inheritance question... (From: Brendan Wilde <email@hidden>)

  • Prev by Date: Object inheritance question...
  • Next by Date: Font info from Applescript
  • Previous by thread: Object inheritance question...
  • Next by thread: Re: Object inheritance question...
  • Index(es):
    • Date
    • Thread