title: Creating proxy object to call methods of target asynchronously (splitting logic/render threads)
body: <p>In my game design I'm trying to allow the logic and render threads to run as parallel as possible. Given this I need some way to push updates from the game logic into the rendering thread, and I'd like to find the cleanest way possible to do this. </p>
  
  <p>Let me firstly apologize in that I'm just a hobbyist and I don't really know any design patterns or the right terminology for this, so if what I'm describing is known by a different name please let me know. </p>
  
  <p>Assume that I have an object which looks something like this, that is continually accessed by the rendering thread:</p>
  
  <pre><code>public class Renderable {
     void functionA(int foo)          { ... }
     void functionB(int foo, int bar) { ... }
     void functionC()                 { ... }
  }
  </code></pre>
  
  <p>I need to call <code>functionA</code> , <code>functionB</code>, and <code>functionC</code> at random points during my logic thread, but because the objects are in different threads I can't directly touch Renderable without concurrency problems. What I really want to do is just create a proxy object <code>RenderableProxy</code> with the same interface as <code>Renderable</code>, which will store all calls to it, and then forward the calls to <code>Renderable</code> during a synchronization window when I have aligned the threads. </p>
  
  <p>The object will look something like this:</p>
  
  <pre><code>public class RenderableProxy {
      Renderable target;
  
      void functionA(int foo)            { ? }
      void functionB(int foo, int bar)   { ? }
      void functionC()                   { ? }
  
      void execute()   {
          foreach( called_function )
             target.???      
      }             
  }
  </code></pre>
  
  <p>Now I trust that I could probably implement this, if I created some struct which held information like an enum representing the function, and stored the parameters, and then just hold this all until I call <code>execute</code>. </p>
  
  <p>But what really annoys me about this is that every time I make an update to <code>Renderable</code> interface, I have to come back to <code>RenderableProxy</code> and modify the interface to match, and modify <code>execute</code> to handle the changes. This feels really messy to me and I feel like there might be a language feature to somehow handle this, such that anytime I change Renderable interface, I don't have to rewrite <code>RenderableProxy</code> to handle the new function.</p>
  
  <p>Is there such a magical feature that will allow me to achieve my goal, without constantly trying to keep interfaces of two different objects (object and its proxy) in sync? I know java has some reflection features, though I'm a bit afraid to touch that as I'm worried about the performance implications of performing reflection lookup a few thousand times per second in a 60Hz game.</p>