Framework design, initialization and framework usage

Robert M. Münch robert.muench at saphirion.com
Tue May 7 10:10:43 UTC 2019


On 2019-05-07 09:06:03 +0000, Kagamin said:

> struct myFramework {
> 	myFrameworkAccessor myFWApp;
> }
> 
> interface myFrameworkApp {
> 	void init();
> }
> 
> main(){
> 	myFramework mf = new myFramework;
> 
> 	mf.myFWApp.init(); // this bombs because myFWApp is NULL
> }
> 
> struct myFrameworkAccessor {
> 	myFrameworkApp instance()
> 	{
> 		if(_instance==null)_instance=new myAppCode();
> 		return _instance;
> 	}
> 	myFrameworkApp _instance;
> 	alias instance this;
> }
> 
> class myAppCode : myFrameworkApp {
> 	void init() {...}
> }

That's a very smart idea... I like it.

Going to take a look if myFrameworkAccessor can be templatized so that 
a user can provide his own class which is then used.

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



More information about the Digitalmars-d-learn mailing list