Re: set parent
Re: set parent
- Subject: Re: set parent
- From: email@hidden
- Date: Tue, 6 Aug 2002 13:24:49 -0700
I have a parser object that does a lot of actions. To make the code
cleaner, I was thinking of putting groups of similar actions into their own
script objects, and have those derive from the parser, which has
results-reporting, file-reading, and string-parsing abilities that the
other objects will want to use. I was hoping I could use delegation instead
of having to do
"tell owner's fileReader to blah blah blah"
each time I wanted to read a file.
So, I'll try to do it with the functionalized method.
Which, actually, brings up a good point. How are people arranging large
object-oriented designs using AS?
What seems to me to be best practice (after only a week, so I may be way
off) is to load script files as if they were factory objects, and then have
a makeNew() handler in the file that would vend a new instance of the
object.
It would seem cleaner if I could just have load script pass parameters, and
then each file would automatically be a factory object. But the added
function isn't too much overhead, and it does add some self-documentation
instead of assuming.
So... what are other people using?
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Seth A. Roby
Scriptwriter Intern
"Life is like an exploded clown. It's really funny until you figure out
what just happened."
has <email@hidden>
Sent by: To: email@hidden
applescript-users-admin@list cc:
s.apple.com Subject: Re: set parent
08/06/2002 06:33 AM
Seth Roby wrote:
>
I am getting an error that I can't set parent to <<script>>, and I think
>
that that's rather odd.
>
>
The situation is as follows:
>
>
foo.scpt----------------------------------------
>
property child : ""
>
>
on run
>
set child to load script file "disk:folder:bar.scpt"
>
tell child to init(me)
>
end run
>
>
bar.scpt--------------------------------------
>
on init(owner)
>
set parent to owner
>
end init
>
>
>
But when I run, I get an error that I "Can't set parent to <<script>>". I
>
thought that setting parents to scripts was the whole point; obviously,
I'm
>
missing something or setting this up wrong.
Alas, you can only set an object's parent when you create it. You cannot
change it once the object exists. Still, consider yourself fortunate you're
not stuck on some boring old traditional class-based language where
inheritance is set in stone at compile-time. At least with AS you have some
degree of flexibility at runtime.
One solution to your problem would be to use a constructor function in
bar.scpt:
-------
--bar.scpt
on newBar(theParent)
script
property parent : theParent
--rest of bar's code here
end script
end newBar
-------
-------
--foo.scpt
property child : ""
on run
set child to newBar(me) of load script (file "disk:folder:bar.scpt")
end run
-------
Though what this is intended for I'm not entirely clear - want to
enlighten?
HTH
has
--
(My email address has changed from <email@hidden> to
<email@hidden>. Please update your address books accordingly.)
_______________________________________________
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.
_______________________________________________
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.