At 1:44 PM -0800 1/18/01, Watson, Christopher wrote:
>The properties within a parent script are equivalent to instance variables.
>But I want to implement the equivalent of a class variable in my parent
>script, so that all child objects created from that parent script can take
>into account the value held within that class variable when performing tasks
>within their instance methods.
>
>Now, in my particular case, I'm not creating discrete child objects that
>each live in a world of their own. All the child objects created from my
>parent script are nodes within a tree (an XML document), with one of those
>child objects representing the root of that tree. The root has child nodes,
>and those child nodes have child nodes, etc. Taking that into consideration,
>I though that I had come up with a fairly simple way of faking a class
>variable.
>
>If I were to maintain the tree as a linked list (meaning, if the parent
>script had a property which held a reference to the child object which is
>its parent node), I would always be able to recurse to the root from any
>node and retrieve the value held within the "class variable" property in the
>root node child object. Since the root node child object never changes for
>the existence of the tree, setting a property value in the root would be the
>same as setting the value for all the children, as long as they all went to
>the root to look for that value.
>
>The problem with this approach is that every time a node is called upon to
>execute its method for forming the textual version of its part of the XML
>document, it must take that walk up the linked list to get the value of that
>property from the root node. It's the same walk for every single element
>within an XML document. And you know how complex XML docs can get.
>
>It works. But it seems terribly ineffient to me.
>
>My questions are:
>
>Is there a better way to implement a class variable in a parent script?
>
>And, is the answer going to be "use a global"? I hope not, because I don't
>want to.
>

I'm guessing that you are coming from a C background?  Not coming 
from that world, I really don't know what a class variable is.  But 
I'll assume that it's a value that every object instantiated from a 
given class would get.  The only way to do something like this would 
be to use a property variable which would be assigned the same value 
in each instance of the object.  You can either assign the value in 
the "new" method to a constant, or, pass in the value:

   property pMyPseudoClassVariable

   on new me
     pMyPseudoClassVariable = 4  -- whatever value
     return me
   end

or, this might be more what you are looking for

   property pMyPseudoClassVariable

   on new me, someValue
     pMyPseudoClassVariable = someValue
     return me
   end

The real question is, who knows what the value of the class variable 
is.  If it's known within the object, use the first approach.  If it 
is known by the thing that instantiates the object, use the second.

Irv
-- 
Lingo / Director / Shockwave development for all occasions.

        (Over two millions lines of Lingo code served!)

[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