ooc-dev team mailing list archive
-
ooc-dev team
-
Mailing list archive
-
Message #00239
Re: Singletons?
Well singletons are more than namespaces, although I kinda hate this
pattern, here it goes:
you can choose to implement 'new' as your get method:
MySingle: class {
_instance := static alloc() as This
new: static func -> This { _instance }
}
if you dislike this (because 'new' sortof implies that it's a new
instance..) just use 'get' instead of 'new', there's not really a
convention here yet
also, there's no special syntax like Scala's object: I actually dislike
this bit of Scala's syntax, it's mostly useful for the main class in
Scala anyway.. (correct me if I'm wrong).
ndd
On Wed, 29 Sep 2010 14:33:01 -0400, Oddity007 <oddity007@xxxxxxxxx>
wrote:
> Easy: Don't.
>
> ooc != Java
>
> If you want a namespace sort of effect, just use namespaced imports:
>
> import Source/Path/Foo into Foo
>
> Foo doSomeStuff(10)
>
> If you can't use namespaced imports (for one-file-monsters), use a
> cover's static methods.
>
> Foo: cover{
> doSomeStuff: static func(argument: Int)
> }
>
> Foo doSomeStuff(10)
>
> On Sep 28, 2010, at 1:16 PM, Damian <damian.pop@xxxxxxxxx> wrote:
>
>> What's the proper or preferred way to create a singleton in ooc? Is > there something specific to do so? (like 'object' in scala, for > example)
>> Thanks!
>>
>> _______________________________________________
>> Mailing list: https://launchpad.net/~ooc-dev
>> Post to : ooc-dev@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~ooc-dev
>> More help : https://help.launchpad.net/ListHelp
>
> _______________________________________________
> Mailing list: https://launchpad.net/~ooc-dev
> Post to : ooc-dev@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~ooc-dev
> More help : https://help.launchpad.net/ListHelp
Follow ups
References