an interesting way to do lazy object caching

BCS ao at pathlink.com
Sat Sep 1 10:26:32 PDT 2007


interface C1{ C1 get();}

class Use : C1{C1 get(){return this;}}

class D
{
	private C1 mine;

	this(){mine = new C2;}

	C1 give(){return mine.get;}

	private class C2 : C1
	{
		C1 get(){ return mine = new Use(); }
	}
}


void main()
{
	D d = new D; // make C2
	C1 c = d.give; // make a C1
	c = d.give; // do not make a C1
}


comments?





More information about the Digitalmars-d mailing list