No facility for statics

0 views
Skip to first unread message

Ajay

unread,
Sep 21, 2009, 5:07:24 AM9/21/09
to noop
Does this imply that the language is also doing away with singletons?

Ajay

Alex Eagle

unread,
Sep 21, 2009, 1:37:06 PM9/21/09
to no...@googlegroups.com
Nope, you just ask the injector for the same instance every time. So you get one instance per injector (just as in Java you get one instance per classloader).

But there's nothing to stop a testsuite from getting one fresh instance per test.
-Alex

Christian Edward Gruber

unread,
Sep 21, 2009, 5:52:00 AM9/21/09
to no...@googlegroups.com
Hi Ajay,

On 2009-09-21, at 05:07 , Ajay wrote:
> Does this imply that the language is also doing away with singletons?

Not entirely - we're getting rid of the standard implementation
practice of a singleton in Java, which would normally look something
like this:

public class Foo {
private static final Foo instance;
private Foo() {
.. do stuff
}
public static Foo getInstance() { return instance; }
}

The above is really hard to test, especially if Foo has a method which
does something like

public Myoutput doBlah() {
return new MyOutput(Bar.getInstance().getRecentValues() / 5);
}

This sort of singleton chaining is death to testability.

But we will support the "once per application" pattern, through scoped
dependency injection.

regards,
Christian.


Christian Edward Gruber
e-mail: christiane...@gmail.com
weblog: http://www.geekinasuit.com/

Reply all
Reply to author
Forward
0 new messages