Suppose we have an application (on the server) that has a set of resources: these resources are indexed by name through a dictionary, that is, Dictionary<string, Resource> resources .
The client sends the names of one or more resources to the server (using WCF) (for example, it sends a List<string> ). There can only be a subset of resources on the server requested by the client, so when the server receives this list, it sends back a list containing only the names of the resources found.
I would like to summarize the search criteria that the client sends to the server so that in the future it will be easy to expand the application (both on the client side and on the server side) with more complex search criteria. To achieve this, I decided to create the ISearchCriteria interface, so the client must send an object of the class that implements this interface.
public interface ISearchCriteria {
However, it seems to me that this solution is not very correct, because the GetComplianceResources method should interact with the dictionary on the server, but the client should not know anything about this dictionary ... I could use a strategy template, linking each specific strategy with specific search criteria. In this way, control logic can be separated from data (i.e., Search Criteria).
UPDATE (strategy template and DTO)
// 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<string> ResourceNames { get; set; } List<int> 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<T> : where T : ISearchCriteria { public List<string> Match(T criteria); } // On the server public class DefaultStrategy : IStrategy<T> where T : DefaultSearchCriteriaDTO { public List<string> Match(T criteria) { // search for resources and returns those found } }
- Is there any design pattern for this purpose?
- Are there any better alternatives?
source share