On Fri, 13 Jul 2007 15:12:47 -0500, Scott Thompson <email@hidden>
said:
I'm working on an AppleScript class for my application and I'd
like to
create some properties that can be defined when an instance of the
class is created, but which are read-only afterward.
For example, the instances of the class include the "name" and
"category" properties. These properties are defined when the
instance
is created, and can be read afterward, but there should not be any
way
to change those properties.
I'm curious about the right way to express that in the sdef and in
the
running application. I envision two scenarios:
1. I mark the properties as "read-only" in the sdef and require the
user to specify the value of those properties in the "with
properties"
parameter of the "make" command. Can a read-only property still be
initialized with the "with properties" parameter?
2. I leave the properties read/write but just return an error if you
try to set the value after the instance is created.
Is either of these scenarios the preferred one?
I don't know if there's a general policy, but I lean towards #2. I
would
provide a really informative error message if the user tries to
change one
of these properties after creation, and also be verbosely
informative in the
dictionary (now that sdefs allow us to be so).
m.
I don't think 2 works (as in my earlier post on this thread).
NSCreateCommand sets all properties from the "with properties"
arguments after initializing the object, so it calls those setters.
Therefore returning an error in the setters will actually return the
error from the 'make' command , which was precisely what the OP tried
to accomplish. Also, the read-only flag in the sdef is only used for
display purposes, and for the users it should look as if they cannot
be set.
As to be verbose in the sdef, to that I fully agree. Probably in the
description of the class, perhaps in the description of the relevant
properties, as appropriate.