> At 5:30 PM +0100 10/12/00, kevin dowd wrote:
>> Hello,
>> 
>> Is having this kind of set up in your Object O.K.
>> 
>> 
>> 
>> on settheProp me, theProp, theVal
>> me[theProp] = theVal
>> end
>> 
>> on broadcastProp me, theProp
>> return me[theProp]
>> end
>> 
> 
> 
> kevin,
> 
> While this certainly works, I wouldn't do that for one important
> reason.  A set of handlers like this assumes that you know the _name_
> of a property within an object.  But you as the programmer should be
> able to change the name of a property within an object without
> affecting the rest of the system.  This is part of the wonderful
> concept of "encapsulation".
> 
> If you want to reach into an object and get and/or set a property by
> name, why not bypass the handler and do it directly (the following is
> strongly discouraged!):
> 
> someObject.somePropertyName = someValue
> 
> and
> 
> someValue = someObject.someProperty
> 
> Instead, I would only build accessor methods for the properties that
> you need to get/set and make the names of these handlers not match
> exactly the name of the property.

Furthermore, I've often found that at some point in a project, I want to
change a object's property from a string to a list, or a linear list to a
property list, or a property list to a nested property list... It's much
easier to deal with an individual set/get method pair than to try to write
generic ones.

Back to the original post, which mentioned passing a project off - here's an
object template that I use for all parent scripts:

property pMyMethods

on new me
  mBuildMethods me
  return me
end
----------------------------------------------------------------
on mBuildMethods me -- Makes a string of all of the methods in this object
for easy reference. Call it in the new method.
  pMyMethods = RETURN
  tempText = (the script of me).text
  repeat with i = 1 to the number of lines in tempText
    if tempText.line[i].char[1..4] = "on m" then
      pMyMethods = pMyMethods & tempText.line[i].char[4..the number of chars
in tempText.line[i]] & RETURN & RETURN
    end if
  end repeat
end

on mGetMethods me -- Returns a string of all of the methods in the object.
  return pMyMethods
end
----------------------------------------------------------------

put gWhateverObj.mGetMethods() will show someone every "public" method in an
existing object - as a convention, I start all public methods with "m", and
private ones with "h". It keeps the object encapsulated, and all one needs
to remember is the mGetMethods() call, which will show all of the other
accessor methods along with whatever comment is placed on the same line as
"on m".

FWIW,
Kurt


[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to the list,
email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo.  Thanks!]

Reply via email to