title: Decouple visualization methods and application
body: <p>this is my first question on SO, so please bear with me.</p>
  
  <p>We develop an application, which gathers data, and we have methods that let us visualize the data in various ways. With growing number of methods, we decided to separate the application and the visualization methods. I'm wondering what is the best way to accomplish this. I've come up with the following code, which somewhat tries to separate the two, but still ...</p>
  
  <p>Is there a better way to do it?</p>
  
  <pre><code>// forward declaration
  class App;
  
  // Interface to all visualization methods
  struct Methods {
      virtual void show(App * a) = 0;
  };
  
  // Some visualization method
  struct Method0 : public Methods {
      void show(App * a) {
          a-&gt;getData();
      }
  };
  
  class App {
  public:
      vector&lt;Methods *&gt; methods;
  
      void run() {
          // draw all registered methods
          for (auto m : methods)
              m-&gt;show(this);
      }
  
      int getData() {
          // parse and precompute data (time-consuming, thus do it only once)
          // return the required data (not just an int..)
          return 42;
      }
  };
  
  void main() {
      App a;
  
      // register some methods
      a.methods.push_back(new Method0());
  
      // run the application
      a.run();
  
      // clean up
      for (auto m : a.methods) delete(m);
  }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>I think Alexander and Petr pointed me in the correct direction, thank you. I'll follow Petr's suggestion and try to separate the data into another class.</p>
  
  <p>Addressing the comment by Spektre:</p>
  
  <ul>
  <li>Developed on Windows (MSVC), otherwise platform independent.</li>
  <li>The visualization is mostly static and changes based on user input. I guess 10 updates per second is an upper bound on the refresh rate.</li>
  <li>What do you mean by data transfer times?</li>
  <li>Memory is not an issue.</li>
  </ul>
  
  <p>The data is a bunch of vectors of objects holding other vectors of objects, 5 dimensions in total. </p>
  
  <p>One visualization is similar to <a href="http://en.wikipedia.org/wiki/Receiver_operating_characteristic" rel="nofollow noreferrer">ROC curve</a>, containing several curves, so we need to traverse part/all the dimensions and compute some statistics. The result is shown in the following figure.
  <img src="https://i.stack.imgur.com/PEWJd.png" alt="visualization example"></p>