As far as I can see there are two main principles how to deal with application-wide role player objects like a root model object (in MVC context):
- create the object and pass it through the object tree (e.g. in the constructor)
- provide it as a singleton or other global variable technique
The first approach seems to be cleaner because the dependencies are better visible but there is a lot of additional work to do (parameters, class variables,…).
What do you prefer?
Edit: The first technique also uses only one instance but it is provided by passing the object and not by a static function
I prefer run singletons’ method
getInstance()as constructor parameter – bake two birds with one stone 😉