Framework design, initialization and framework usage
Adam D. Ruppe
destructionator at gmail.com
Mon May 6 17:04:47 UTC 2019
On Monday, 6 May 2019 at 16:50:14 UTC, Robert M. Münch wrote:
> myFramework mf = new myFramework;
I'd make that thing's constructor private, and then offer a
helper template function that actually creates it and the user
passes a type.
---
// inside your library
struct myFramework {
private MyFramework app;
private this(MyFramework app) {
this.app = app;
}
}
myFramework initializeMyFramework(FrameworkClass)()
if(is(FrameworkClass : myFrameworkApp))
{
return myFramework(new FrameworkClass());
}
---
Then the user's code would look something like this:
---
import my_framework;
class myAppCode : myFrameworkApp {
// implementations....
}
void main() {
auto thing = initializeMyFramework!myAppCode;
// if you have other stuff to do with thing, you can here.
}
---
More information about the Digitalmars-d-learn
mailing list