Re: Script Objects
Re: Script Objects
- Subject: Re: Script Objects
- From: "Mark J. Reed" <email@hidden>
- Date: Tue, 19 Jan 2010 10:49:37 -0500
On Tue, Jan 19, 2010 at 9:30 AM, Luther Fuller <email@hidden> wrote:
> Is there any advantage to associating the data and the handlers for the data
> by using a script object?
Mainly, the fact that the code using the script object doesn't have to
know or care about the innards of the script object. You can have any
number of script objects, all with completely different "SayHello"
handlers that have nothing to do with each other; pass the object to a
handler that calls the object's SayHello, and it will work, even
though the handler doesn't know anything about what properties each of
the objects has, how or if they're linked in parent: chains, etc. To
get that effect with your code2 style, you'd have to write different
methods, SayHello1, SayHello2, etc.
for instance:
script Folks
property parent: Person
on SayHello()
set message to "Howdy, I'm " & (my FullName) & "!"
say message
end SayHello
end script
copy Person to Elmer
set Elmer's FullName to "Elmer J. Fudd"
set Elmer's Title to "Millionaire"
copy Folks to Foghorn
set Foghorn's FullName to "Foghorn J. Leghorn"
repeat with someone in {Elmer, Foghorn}
someone's SayHello()
end repeat
It would be purer object-oriented style if we weren't setting the
objects' properties from outside the object; there should really be
handlers to do that for us, or better yet, a "constructor" that does
the copy/initialize in one swell foop. But even though AppleScript
has objects and message-passing all over the place, it's not really
designed as a traditional object-oriented language.
--
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:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden