www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - design question, gtkd object interdependence

I have a design question about (i guess) object interdependence 
using gtkd.

There is an application class which sets its property mAppWin. 
The app is passed as an argument to the window constructor. 
During the window constructor a scale (trackbar) is created which 
also receives and stores an app reference to later update other 
elements during an onChange event. The scale can access 
mApp.mSomeData to set its initial value because app has been 
passed down. The call to setValue() now triggers onValueChanged() 
which wants to access the mAppWin property of the app to update a 
canvas. Since all this happens during the initial 'new AppWin()' 
call in App, the app's mAppWin property is not set yet, so 
onValueChanged() will crash.



class App : Application
{
	AppWin mAppWin;

	void onActivate(GioApplication gioApp)
	{
		mSomeData = 123;
		
		mAppWin = new AppWin(app, [...]);



class AppWin : ApplicationWindow
{
	Scale1 mScale1;

	this(Application application, [...])
	{
		mScale1 = new Scale1(0, 100, 1, app);   // (app is application 
casted)



class Scale1 : VScale
{
	App mApp;

	this([...], App app)
	{
		[...]
		mApp = app;
		[...]
		setValue(max * mApp.mSomeData);
	}

	void onValueChanged(Range range)
	{
		//if (mApp.mAppWin)
			mApp.mAppWin.mCanvas.update();   // mAppWin not set yet, 0



I have several question in mind:
- Is it a bad idea to pass an app around that contains everything 
for everywhere?
- Should the app pass the data for the initial scale value 
through the window constructor? Or should it set the scale value 
after initialization is done?
- How would the scale update the canvas without keeping/walking 
through a DOM like this. Maybe some asynchronous messaging?

While I could make it work, I wonder what the actual problem is 
and what it's called like.
Mar 25