[Laszlo-dev] Singleton Class pattern [Was: any idea what this code in LzModeManager is, doing?]

Donald Anderson dda at ddanderson.com
Fri Mar 21 12:32:14 PDT 2008


I don't think this works.
I know that java/C++ expects constructors
to be void (allow no returns).  It looks like SWF8/DHTML
are the same (except they don't complain).

I just tested by putting SingletonClass into the lfc and
running with:

<canvas>
   <simplelayout />
   <text name="status0" />
   <text name="status1" />
   <text name="status2" />
   <text name="status3" />
   <text name="status4" />

   <script>
     var s1 = new SingletonClass;
     var s2 = new SingletonClass;
     var f1 = new Foo();
     var f2 = new Foo();
     if (s1 == s1) {
         status0.setText("sanity check");
     }
     if (s1 == s2)  {
         status1.setText("yes match");
     } else {
         status1.setText("no match");
     }
     if (f1 == f2)  {
         status2.setText("foo match");
     } else  {
         status2.setText("no foo match");
     }

   </script>
</canvas>

and I see that s1 != s2.  That is, I get
'sanity chck'
'no match'
'no foo match'

- Don

On Mar 21, 2008, at 2:55 PM, P T Withington wrote:

> This is my pattern for singleton classes:
>
> class SingletonClass {
>  static var singleton;
>  function SingletonClass() {
>    if (SingletonClass.singleton) {
>      return SingletonClass.singleton;
>    } else {
>      SingletonClass.singleton = this;
>    }
>    // implicitly returns this
>  }
>  SingletonClass.singleton = new SingletonClass;
>
>  ...
> }
>
> I think that is better than making a class with all static methods  
> as it allows you to program in more familiar terms of an instance.
>
> On 2008-03-21, at 14:35 EDT, André Bargull wrote:
>> LzModeManager gets additional methods in lfc/services/platform/swf  
>> resp. lfc/services/platform/dhtml, i.e. "__findInputtextSelection".
>>
>>> I'm asking because I wanted to try to convert LzModeManager to a  
>>> class with only static vars, and this is the only thing that  
>>> looked like it would cause trouble with that plan. On Fri, Mar 21,  
>>> 2008 at 1:55 PM, Henry Minsky <henry.minsky at gmail.com> wrote:
>>>> >      In handleMouseEvent, the last line is this:
>>>> >
>>>> >    this[ "haveGlobal" + eventStr ] = false;
>>>> >
>>>> >
>>>> > Any idea what it is setting this for?
>>>> >
>>>>
>>>
>>> Also, there's a line
>>>
>>>       if (view == null ) {  // check if the mouse event is in a  
>>> inputtext
>>>           view = __findInputtextSelection();
>>>       }
>>>
>>> for which I cannot find the definition of __findInputTextSelection  
>>> anyplace
>>> (?)
>>>
>>>
>>>
>>>> >
>>>> > --
>>>> > Henry Minsky
>>>> > Software Architect
>>>> > hminsky at laszlosystems.com
>>>> >
>>>> >
>>>>
>>>
>>>
>>> -- Henry Minsky Software Architect hminsky at laszlosystems.com
>>
>
>


--

Don Anderson
Java/C/C++, Berkeley DB, systems consultant

voice: 617-547-7881
email: dda at ddanderson.com
www: http://www.ddanderson.com







More information about the Laszlo-dev mailing list