title: Looking for a Command Pattern Alternative
body: <p>I have written a Test Automation Framework.  The framework is build around objects and actions.  An object might be a text box.  The actions for it might be things like set-text, clear, verify-text, verify-enabled, etc.  The framework is independent of the acitons, so we can add more actions over time without having to respin the framework itself.  I considered two approaches for the actions.  The first was to use the command pattern.  In this case I would have an interface that looks something like this:
  <br/></p>
  
  <blockquote>
    <p><code>public interface IAction</code><br/>
    <code>{</code><br/>
    <code>void Execute(StringDictionary properties);</code><br/>
    <code>}</code><br/></p>
  </blockquote>
  
  <p>The issue is that we would end up with many of these command classes.
  <br/></p>
  
  <blockquote>
    <p><code>public class SetTextAction : IAction</code><br/>
    <code>{</code><br/>
    <code>public void Execute(StringDictionary properties)</code><br/>
    <code>{</code><br/>
    <code>}</code><br/>
    <code>}</code><br/>
    <br/>
    <code>public class ClearAction : IAction</code><br/>
    <code>{</code><br/>
    <code>public void Execute(StringDictionary properties)</code><br/>
    <code>{</code><br/>
    <code>}</code><br/>
    <code>}</code><br/>
    <br/>
    <code>public class VerifyTextAction : IAction</code><br/>
    <code>{</code><br/>
    <code>public void Execute(StringDictionary properties)</code><br/>
    <code>{</code><br/>
    <code>}</code><br/>
    <code>}</code><br/>
    <br/>
    <code>public class VerifyEnabledAction : IAction</code><br/>
    <code>{</code><br/>
    <code>public void Execute(StringDictionary properties)</code><br/>
    <code>{</code><br/>
    <code>}</code><br/>
    <code>}</code><br/></p>
  </blockquote>
  
  <p>Furthermore any shared code will need to be in yet another class.  It seems to increase the noise to signal ratio in the code.<br/>
  <br/>
  The alternative I have come up with is to use a utility class for the type and methods for the actions.  This ends up looking like this:
  <br/></p>
  
  <blockquote>
    <p><code>public class TextboxActions</code><br/>
    <code>{</code><br/>
    <code>public static void set-text(StringDictionary properties)</code><br/>
    <code>{</code><br/>
    <code>}</code><br/>
    <code>public static void clear(StringDictionary properties)</code><br/>
    <code>{</code><br/>
    <code>}</code><br/>
    <code>public static void verify-text(StringDictionary properties)</code><br/>
    <code>{</code><br/>
    <code>}</code><br/>
    <code>public static void verify-enabled(StringDictionary properties)</code><br/>
    <code>{</code><br/>
    <code>}</code><br/>
    <code>}</code><br/></p>
  </blockquote>
  
  <p>This has the advantage that the code for textboxes is all together.  In addition, any code that is common to multiple actions can be in the same class.  Unfortunately, this approach requires that I use reflection to "find" the action method.  This is obviously not type safe and can be time consuming.  It is slow enough that I have added a cache so I do not have to find the same action twice, but this adds to the code complexity.</p>
  
  <p>Either of these solutions works, but they both have undesirable characteristics.  Is there an alternative approach to this problem that someone can suggest?</p>