Proxy class/handle vs subclass
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/825018/pimpl-idiom-vs-pure-virtual-class-interface">Pimpl idiom vs Pure virtual class interface</a>  </p>
</blockquote>



<p>In hiding implementation, I've read a lot about the "proxy class" or "handle class" or "cheshire cat smile" technique where you essentially include a pointer to your "real" class as a data member in your public/proxy class, and then implement everything in the "real" class.</p>

<p>But I was looking at some sample code and noticed another technique that seems to be easier, as it doesn't require you to also write the "dummy" methods in the handle class to then call the real methods in the handle class, nor does it require any data members at all, and overall just seems more streamlined.</p>

<p>The technique is to simply define all your public methods as a <code>struct</code> (or a class where everything is <code>public</code>) and all <code>virtual=0</code> member functions with nothing more. Thus there is no implementation. Then, define a static function that returns a pointer to this <code>struct</code> so the client can use the class. But behind the scenes this method actually returns a subclass of the struct, where you can then have much more going on inside this subclass.</p>

<p>If this is so straightforward and I would argue is more elegant than a public class including a data member that is a pointer to a separate class, and having to implement the public class's calls to the data member's methods, then why isn't this the technique most discussed in hiding implementation?</p>
