title: How to use polymorphism to execute command on objects, which have no common base class?
body: <p>I am receiveing commands through json, which I insert in to a pipe. For this reason thye must have the same base class.
  The pipe is read by a pipe handler, some commands are consumed by the pipe handler, others have to be passed down to a device, which is a member of the pipe handler. I could simply do this:</p>
  <pre><code>class Command{};
  class HandlerCommand : public Command {
     void execute(Handler* h);
  };
  class DeviceCommand : public Command {
     void execute(Device* d);
  };
  
  Command* c = pipe.receive();
  if (const auto hc  = dynamic_cast&lt;const HandlerCommand*&gt;(c)) { hc.execute( **handlerptr** ); }
  else if (const auto dc  = dynamic_cast&lt;const DeviceCommand*&gt;(c))  { dc.execute( **deviceptr** );}
  </code></pre>
  <p>Device and pipehandler should not have the same base, since they have no common methods, fields, they are conceptually different.
  Is there a way to avoid using dynamic cast here. I was thinking maybe there is some neat design pattern for this, but couldn`t quit come up with a better solution.</p>
  <p>EDIT: did not derive DeviceCommand and HandlerCommand from command, fixed this.</p>