Best practice for accessing Application Object

Hi,



I am currently implementing some custom controls and some of them need to communicate with app states.

Is there any best practice™ for accessing app states or the app object from a control?

At the moment I am passing the application object in the constructors of the controls, but I wish there was an more independent way to do this, so that I don’t need to pass the application object to all the controls that need it.



[java]

public class CustomControl extends AbstractControl {

protected Application app;

public CustomControl(Application app) {

this.app = app;

}

}

[/java]



Regards,

Niclas

Make your main application a Singleton (and perhaps use double checked locking if you need to) and you can access it more easily.

Edit: I probably should not answer questions quickly in the middle of the night… reread the question and norman is right about a Singleton not being commonly considered best practice in this case.

@Tumaini said:
Make your main application a Singleton (and perhaps use double checked locking if you need to) and you can access it more easily.

Thats definitely not "best practice™" ^^ Best practice would be knowing where you need the application (or appStateManager) to reference it for the Controls (which maybe just need a certain app state..?) and then making sure you have it there. jME2 suffered a lot from static accessors as they mostly just make it too easy to create "spaghetti code" through lots of references from all over the application to those accessors.