Re: OO Theory misconceptions (was Re: can I make a list of
Re: OO Theory misconceptions (was Re: can I make a list of
- Subject: Re: OO Theory misconceptions (was Re: can I make a list of
- From: email@hidden
- Date: Thu, 31 Jan 2002 23:55:03 -0500
On Fri, 01 Feb 2002 10:18:18 +1100, Timothy Bates <email@hidden> stated,
>
> tell object_template to clone_oneself given desired_name:"Fred"
>
> set Fred to the result
>
> tell Fred to disclose_thy_name()
>
>
That is a very cool example, but I think what is missing is the ability to
>
have an initialisation handler called on load script
>
>
Set bill to load script file.lib
>
>
bill's birthday()
>
--> "I was born on 1/2/02"
>
>
Where on load script, a handler called initialise() is called, which does
>
some setup and creation-time stuff (in this case, setting a birthday
>
property).
There are many cases when I wish I had an initializer for script objects, and
sometimes a destructor. (Particularly for a logging object, where I'd like to
close a log file or log window when the script terminates.) Perhaps that's one
reason I like constructor functions.
If you are using a loadable library, you can put the constructor in the library,
and ask it to pop out the object you want. But I'll admit it seems a bit bulky:
set factory to load script alias "File with no freekin' Windows extension"
tell factory to makePerson() returning bill
bill's birthday()
There, makePerson() does the initialization calculations. (A constructor
doesn't have to contain *just* the script object. It can look like this:
to makePerson()
set today to current date
if day of current date is 29 and month of current date is February
script
property character : "Frederick, apprentice pirate"
property birthday : today
-- various tenor handlers
end script
else
script
property character : "Pirate King"
property birthday : today
-- various baritone handlers
end script
end if
end makePerson
It seems cluttered, because you have this script object "factory" which was used
once and hangs around uselessly. But if you think of "factory" as the object
class, it doesn't seem too bad. (And "factory" is really where the handler code
for the constructed objects actually lives.)
--
Scott Norton Phone: +1-703-299-1656
DTI Associates, Inc. Fax: +1-703-706-0476
2920 South Glebe Road Internet: email@hidden
Arlington, VA 22206-2768 or email@hidden