title: Abstract class - hiding implementation in C++ practice
body: <p>Recently I've been writing code similar to this:</p>
  
  <p>messagehandler.h:</p>
  
  <pre><code>#include "message.h"
  class MessageHandler {
  public:
     virtual ~MessageHandler() {}
     virtual void HandleMessage(Message *msg) = 0:
  };
  </code></pre>
  
  <p>persistmessagehandler.h:</p>
  
  <pre><code>MessageHandler *CreatePersistMessageHandler();
  </code></pre>
  
  <p>persistmessagehandler.cpp:</p>
  
  <pre><code>#include "messagehandler.h"
  #include "persist.h"
  
  class PersistMessageHandler : public MessageHandler {
  private:
     PersistHandle ph;
     size_t count;
     InternalCheck();
  public:
     PersistMessageHandler(int someParam);
     virtual ~PersistMessageHandler ();
     virtual void HandleMessage(Message *msg):
  };
  PersistMessageHandler::PersistMessageHandler(int someParam)
  {
    ph.Initialize();
  }
  ... rest of implementation.
  
  MessageHandler *CreatePersistMessageHandler(int someParam)
  {
    return new PersistMessageHandler(someParam);
  }
  </code></pre>
  
  <p>The reasoning here is to hide the PersistMessageHandler. Clients don't need to include a header for the PersistMessageHandler class, with all the includes and types the implementation might need, and to more cleanly seperate the interface and implementation. 
  . It'll always be dynamically allocated anyway, </p>
  
  <p>All PersistMessageHandler users will just call CreatePersistMessageHandler(..); directly or indirectly get one from a factory.</p>
  
  <p>But. I've not seen this approach used much elsewhere. Is the above good practice ? Are there other/better alternatives for simple cases ?</p>