Polymorphic Command Parser Design
<p>Would love some opinions on this problem I'm trying to workout.  I'm trying to improve my OO experience and fully leverage C++'s polymorphic capabilities.  I'm trying to write some code for a basic command parser.  They command structure goes as so:</p>

<p>[command name] [arguments]</p>

<p>The command name will just be limited to a one word string. The arguments can be a 0 to N list of strings.</p>

<p>Each command and list of arguments could be directed to any variety of software objects in my system.  So for example I could have an rtp statistics command map to my rtp module,  the user statistics to my user module.  Something like that.  </p>

<p>Right now the entry point for my CLI provides the entire command string as a standard string.  And it provides a standard output stream for displaying results to the user.</p>

<p>I really want to avoid using a parser function and then doing an if then else kind of deal.  So I was thinking something like this:</p>

<ol>
<li>I would have a base class called command.  Its constructor would take the string command, the stdout, and an interface for the object it needs to interact with.</li>
<li>I would create a command factory that would match the command name to the object that handles it.  This would instantiate the right command object for the right command.</li>
<li>Each separate command object would parse the given arguments and make the right choices for this command.</li>
</ol>

<p>What I'm struggling with is how to give the right module to the right command.  Is this where I should use a template argument?  So that each command can take any interface and I'll let the factory decide which module to pass in to the command object?</p>

<p>I'm also open to other opinions as well.  I'm just trying to learn and hoping the community can give me some tips :-).</p>
