• 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: Inheritance implementation question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inheritance implementation question


  • Subject: Re: Inheritance implementation question
  • From: Paul Berkowitz <email@hidden>
  • Date: Tue, 09 Apr 2002 10:11:49 -0700

On 4/9/02 9:36 AM, "Brennan" <email@hidden> wrote:

> Well I want to be able to make generic skeleton scripts where you can set the
> subtype *once* and then use it to create objects of that subtype later,
> something like:
>
> set subtype to Thing type -- this is set one place and one place only

I'm not sure I've got your point exactly: i.e., are you just trying to save
yourself scripting the alternatives, or is it something that will be helpful
at runtime, avoiding the "if/else if" routine over and over and over again?
If the latter, you might want to make script objects, all named differently,
but all having a handler named the same, each of which sets the subtype
differently. Then you can do the "if/then" per type, thing just once to set
a variable to the correct script object. From then on you just tell the
script object (by variable) to do its handler, which can take as many
parameters as you need to set all the other properties too.

E.g., you have your three script objects:

script ThingType
on SetType(otherstuff)
make new SuperThing with properties {type:Thing,
everythingElse:otherstuff}
end SetType
end script

script ThangType
on SetType(otherstuff)
make new SuperThing with properties {type:Thang,
everythingElse:otherstuff}
end SetType
end script


script ThungType
on SetType(otherstuff)
make new SuperThing with properties {type:Thung,
everythingElse:otherstuff}
end SetType
end script


Then, when your newborn item comes into the room for the first time, you do
the if/then routine, or even get around it with a handler like this that
does it for you (in fact, maybe that's all you want here):

to CollectUniqueItemIndex(theList, theItem) -- the Item can be string,
number, constant, app object or list

local aListMember

script listScript -- this speeds things up for long lists
property listRef : theList
end script

repeat with i from 1 to (count theList)
set aListMember to item i of listScript's listRef
if aListMember = theItem then
set theIndex to i
exit repeat
end if
end repeat

return theIndex

end CollectUniqueItemIndex

------
Now, you're all set up, or almost:


set thingList to {thing, thang, thung}
set scriptList to {ThingType, ThangType, ThungType}


OK, runtime dawns, otherstuff has been determined, and 'subType' enters the
room: it could be thing, thang, or thong, we know not yet:


set x to CollectUniqueItemIndex(thingList, subType)
set SuperScript to item x of scriptList

tell SuperScript to set superThing to SetType(otherstuff)




This can go on all day, with as many instances as of many subtypes as you've
got.


--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: OS X Shutdown Folder
  • Next by Date: Re: Finder Version Wrong in OS X
  • Previous by thread: Re: OS X Shutdown Folder
  • Next by thread: Re: Inheritance implementation question
  • Index(es):
    • Date
    • Thread