Getting commands from string input
<p>I have a program which gets commands as a string. Each character in the string represents a command. An example of command is given below</p>

<pre><code>OBIPC
</code></pre>

<p>O - Open a file</p>

<p>B - Make the text in Bold</p>

<p>I - Make the text in italics</p>

<p>P - Print the text</p>

<p>C - Close the file</p>

<p>My program has to parse this string and do respective job. Each command is executed sequentially. I came up with the following idea to do this.</p>

<ol>
<li>Create action classes for each command. Each will have a <em>Execute()</em> method and implements an interface <em>IExecutable</em>. So if I have 5 commands, I will have 5 classes each for processing each command. </li>
<li>Keep the command and associated object that can perform action in an  associative container (<em>std::map</em> in C++ and <em>Dictionary</em> in .NET).</li>
<li>Loop through each character in the input string. Check any action associated for each character. If yes, get the action object and call <em>Execute()</em>. Some sort of command design pattern. If some charcters don't have action associated, throw error or skip. </li>
</ol>

<p>Will this approach be the best for my problem or do you see any easy/efficient method to do this? This is not specific to any programming language, I am OK with any programming language. All I am looking for is ideas to do this.</p>

<p>Any thoughts?</p>
