The answer is I am used to Java, C# etc and just tried to ape those methods. I 
hadnt thought about using locales.

--- Original Message ---

From: "Marshall Lochbaum" <[email protected]>
Sent: August 13, 2014 10:30 PM
To: [email protected]
Subject: Re: [Jprogramming] Singleton Objects in J

I'm confused as to why you would use a singleton object over a named
locale. A named locale is easy to locate and can be assigned to a noun
just like a numbered locale. It's also impossible to create another copy
of the locale.

Marshall

On Wed, Aug 13, 2014 at 10:25:54AM +0100, Jon Hough wrote:
> I looked through the jsoftware website but couldn't find any references 
> tocreating singleton objects in J.So I created my own singleton pattern for 
> J. It seems to work.
>
> coclass 'Singleton'
>
> NB. static instanceinstance =: 0
>
> NB. private constructorcreate =. verb defineval =: 1)
>
> NB. Public gettergetinstance =: verb defineif. instance = 0 do. instance =: 
> conew 'Singleton'instanceelse. instanceend.)
>
> NB. Verb for checking.say =: verb defineval =: val + 100t =. 'HEY't)
>
> destroy =: codestroy
>
> One thing is, I'm not sure whether making create private stops conew being 
> called explicitly.To create THE instance or get it, the user should call 
> getinstance_Singleton_ ''
> But users can still call conew 'Singleton' from outside the class without an 
> error being raised.
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to