Singletons importing each other?

Jack via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jul 24 08:07:20 PDT 2016


Is there a way for singletons that import each other, use each 
other's functions?

Like i.e:

------
module sing1;
import sing2;
final class Singleton_1{

static this{
instance = new Singleton_1();
}

static Singleton_1 getInstance(){
return instance;
}

void foo(){
writeln("Sample");
}

void bar2(){
Singleton_2.getInstance().bar();
}

private:
static Singleton_1 instance;
}

-------
module sing2;
import sing1;
final class Singleton_2{

static this(){
instance = new Singleton_2();
}

static Singleton_2 getInstance(){
return instance;
}

void bar(){
Singleton_1.getInstance().foo();
}

private:
static Singleton_2 instance;
}

without triggering the "cycle between modules with 
constructors/destructors"?



More information about the Digitalmars-d-learn mailing list