title: How do I avoid using a global for the data behind a GUI?
body: <p>I am writing an audio processing standalone application. I have an <code>AudioManager</code> object that wraps things to do with the engine (such as I/O device management, signal processing routing, running state). I am writing a GUI to control the <code>AudioManager</code> running in the background. Currently, every component that needs to message the <code>AudioManager</code> needs a pointer to it. </p>
  
  <p>This starts to get crazy when a deeply nested object needs a pointer to the <code>AudioManager</code>, as it means that I need to pass the pointer through the constructors of GUI objects that don't directly care about <code>AudioManager</code> (only some subcomponents need to know).</p>
  
  <p>I could just make <code>AudioManager</code> a singleton to avoid the boilerplate, but the information flow from the class is bidirectional, so this is probably a bad idea. I does also feel a little fishy wrapping everything into a big class, but it makes it a little easier to pass about. Is there a common pattern to avoid the mindless pointer passing?</p>
  
  <p>Below is a bit of pseudocode showing some constructors highlighting the basic type of problem. I've tagged this C++11 to see if that gives any unique solutions.</p>
  
  <pre><code>MainWindow()
  {
      am = new AudioManager();
      someWidget = new SomeWidget(am);
  }
  
  SomeWidget(AudioManager* am_) //SomeWidget does not really care about am
  {
      someSubComponent = new SubThingy(am_);
  }
  
  SubThingy(AudioManager* am_) : subThingyLocalAudioManagerPtr(am_)
  {
      subThingyLocalAudioManagerPtr-&gt;registerSomethingOrOther(this);
  }
  </code></pre>