title: How can I design a general search criteria?
body: <p>Suppose we have an application (on a server) that has a set of resources: these resources are indexed by name through a dictionary, that is <code>Dictionary&lt;string, Resource&gt; resources</code>.</p>
  
  <p>The client sends to the server (using WCF) the names of one or more resources (for example, it sends a <code>List&lt;string&gt;</code>). On the server there may be only a subset of the resources requested by the client, so when a server receives this list, it sends back a list containing only the names of found resources.</p>
  
  <p>I would like to generalize the search criteria that the client sends to the server, so that in future it is easy to extend the application (both client-side and server-side) with a more complex search criteria.
  To achieve this goal, I thought to create the <code>ISearchCriteria</code> interface, so the client should send an object of a class which implements this interface.</p>
  
  <pre><code>public interface ISearchCriteria
  {
      // the names of the resources which match with the search criteria
      ICollection&lt;string&gt; GetCompliantResources();
  }
  </code></pre>
  
  <p>However it seems to me that this solution is not very correct, because the <code>GetComplianceResources</code> method should interact with the dictionary on the server, but the client should not know anything about this dictionary...  I might use the <em>strategy pattern</em>, associating each concrete strategy to the specific search criteria. In this way could separate the control logic from the data (ie. the search criteria).</p>
  
  <p><strong>UPDATE (strategy pattern and DTO)</strong></p>
  
  <pre><code>// Both on the server and on the client
  public interface ISearchCriteria
  {
      // empty
  }
  
  // Both on the server and on the client
  public class DefaultSearchCriteriaDTO : ISearchCriteria
  {
      List&lt;string&gt; ResourceNames { get; set; }
      List&lt;int&gt; OtherCriteria { get; set; }
  }
  
  // Both on the server and on the client
  public class MySearchCriteriaDTO : ISearchCriteria
  {
      string SearchString { get; set; }
  }
  
  // On the server.
  public interface IStrategy&lt;T&gt; : where T : ISearchCriteria
  {
      public List&lt;string&gt; Match(T criteria);
  }
  
  // On the server
  public class DefaultStrategy : IStrategy&lt;T&gt; where T : DefaultSearchCriteriaDTO
  {
      public List&lt;string&gt; Match(T criteria)
      {
          // search for resources and returns those found
      }
  }
  </code></pre>
  
  <ul>
  <li>Is there some design pattern for this purpose?</li>
  <li>Are there better alternatives?</li>
  </ul>