Hello,
I am working on an application with a GUI using wxWidgets. I got an object used as a "model": its data has to be used to draw the ui and the ui should modify it. Let's call this class Model
.
The structure of the applications looks like this:
A wxApp
-derived object, that possesses:
- a
wxFrame
-derived object, that possesses awxGLCanvas
-derived object. - another
wxFrame
-derived object.
For the Model
class,
I could use a singleton that would make things very simple: I could just use
model.getThatData()
ormodel.setThatData()
anywhere.However, I can't disagree when people say that it's a global variable with a fancy dress.
I could also use dependency injection (or is it something else): I instanciate
Model
in thewxApp
object, and then I pass a reference to the instancemodel
in the constructors of bothwxFrame
-derived classes, same thing withwxGLCanvas
constructor, and I store the reference as an attribute of the needed classes.However, this doesn't seem either a very good solution. Suppose the first
wxFrame
object doesn't need to usemodel
. We will nontheless have to pass a reference tomodel
in its constructor to be able to pass it to thewxGLCanvas
-derived object. So that design could lead to many (?) unnecessary passings.- ?
What do you think ? I have been asking myself this question for a long time...