title: Generic Search Criteria Type
body: <p>I've my application structured using presentation layer, service layer and data access layer. There are multiple services and APIs which often need to retrieve some data from the data access layer. To get such data, I often need to pass some search criteria from one layer to another. For example, I could be passing attributes like from_date, to_date, email_id, user_id etc. Now instead of passing a lot of individual parameters, I am trying to pass an object, say SearchCriteria. Again, different services/apis need different SearchCriterias. </p>
  
  <p>The question is, how do I make it generic so as to make it usable by all services. One way is to have a SearchCriteria object which holds a map of SEARCH_KEY to value, where SEARCH_KEY could be an enum (having values like FROM_DATE, TO_DATE etc). Depending on the SEARCH_KEY, I could retrieve the key and use it. But this works only when you one layer knows about the type of the value (Integer, String) to expect from this map. One layer is coupled to another, which I suppose isn't good. I went through this question - <a href="https://stackoverflow.com/questions/10429230/map-with-multiple-value-types-with-advantages-of-generics">Map with multiple value types with advantages of generics</a> which solves a similar problem. Is that a good design? Are there any better alternatives?</p>