[Gambas-user] Hi da crevette world
Benoit Minisini
gambas at ...1...
Thu Dec 20 13:19:47 CET 2007
On mercredi 19 décembre 2007, Mickaël Wolff wrote:
> Hi folks,
>
> I'm Mickaël Wolff, and i'm a french programmer living in Alsace
> (France). So I was disgusting by the MSVB years ago, and I hope Gambas
> to make Basic less bad to my eyes.
>
> That said, I would like to know where are they archives from this
> mailing list, and its FAQ. Just to not ask again about some stupid
> questions.
>
> I this time, I'll give you the question that push me to this list. I
> tried to make a singleton class. To to that, I need a private method
> _new. I check some documentation, and I reach on static class. Is that
> the way to implement singleton ?
>
> Thanks ! And thanks to have write Gambas.
You can use the CREATE STATIC keyword, and the class name as the only
instance.
Note that it won't prevent anyone else to instanciate the class. An example of
that is the Setting class in the gb.settings component.
If you really want to prevent the instanciation, you can put that in the
constructor:
PUBLIC SUB _new()
IF Class[Object.Type(ME)].Count > 1 then Error.Raise("Singleton class")
END
Regards,
--
Benoit Minisini
More information about the User
mailing list