The following declaration implements the classic singleton
design pattern and uses D's static opCall feature to make
for brevity of use, that is to say, you can access the singleton
instance by simply writing Foo() rather than Foo.instance.
Furthermore, the use of private on the static instance f
On Sun, 27 Jun 2010 09:36:04 +0930, Justin Johansson wrote:
> immutable class Foo
> {
> static private Foo instance;
>
> static this() { // line 9
>instance = new Foo;
> }
>
> static Foo opCall() { // line 13
>return instance;
> }
Michal Minich wrote:
On Sun, 27 Jun 2010 09:36:04 +0930, Justin Johansson wrote:
immutable class Foo
{
static private Foo instance;
static this() { // line 9
instance = new Foo;
}
static Foo opCall() { // line 13
return instance;
On Sat, 26 Jun 2010 20:19:44 -0400, Michal Minich
wrote:
On Sun, 27 Jun 2010 09:36:04 +0930, Justin Johansson wrote:
immutable class Foo
{
static private Foo instance;
static this() { // line 9
instance = new Foo;
}
static Foo opCall() {
Steven Schveighoffer wrote:
On Sat, 26 Jun 2010 20:19:44 -0400, Michal Minich
wrote:
On Sun, 27 Jun 2010 09:36:04 +0930, Justin Johansson wrote:
immutable class Foo
{
static private Foo instance;
static this() {// line 9
instance = new Foo;
}
static Foo
On Mon, 28 Jun 2010 08:07:40 -0400, Justin Johansson wrote:
Steven Schveighoffer wrote:
On Sat, 26 Jun 2010 20:19:44 -0400, Michal Minich
wrote:
On Sun, 27 Jun 2010 09:36:04 +0930, Justin Johansson wrote:
immutable class Foo
{
static private Foo instance;
static this() {
Steven Schveighoffer wrote:
On Mon, 28 Jun 2010 08:07:40 -0400, Justin Johansson wrote:
Steven Schveighoffer wrote:
btw. The reason I marked the static instance member as private
was simply to enforce stylist use of Foo() rather than Foo.instance
Yuck Foo().xyz :)
But, whatever floats your
On Mon, 28 Jun 2010 08:40:36 -0400, Justin Johansson wrote:
Steven Schveighoffer wrote:
On Mon, 28 Jun 2010 08:07:40 -0400, Justin Johansson
wrote:
Steven Schveighoffer wrote:
To go one step further, if you want it to truly be a singleton type,
you should mark the constructor private.
Steven Schveighoffer wrote:
On Mon, 28 Jun 2010 08:40:36 -0400, Justin Johansson wrote:
Steven Schveighoffer wrote:
On Mon, 28 Jun 2010 08:07:40 -0400, Justin Johansson
wrote:
Steven Schveighoffer wrote:
To go one step further, if you want it to truly be a singleton type,
you should mark
Steven Schveighoffer wrote:
On Mon, 28 Jun 2010 08:07:40 -0400, Justin Johansson wrote:
Steven Schveighoffer wrote:
On Sat, 26 Jun 2010 20:19:44 -0400, Michal Minich
wrote:
On Sun, 27 Jun 2010 09:36:04 +0930, Justin Johansson wrote:
immutable class Foo
{
static private Foo instance;
10 matches
Mail list logo