title: repository pattern with specification pattern in java
body: <p>I am trying to implement the repository pattern to query users and the corresponding settings associated to each user. I am having a repository interface which has the crud operations to be implemented by each and every repository.</p>
  
  <pre><code>import java.util.List;
  
  public interface Repository&lt;T&gt; {
  
      void add(T item);
      void add(Iterable&lt;T&gt; items);
      void update(T item);
      void remove(T item);
      void remove(Specification specification);
      List&lt;T&gt; query(Specification specification);
  
  }
  </code></pre>
  
  <p>I am reading about the specification pattern but i do not understand how to apply the concept to my usecase.</p>
  
  <p>I have two repositories which implements the Repository interface. My classes will be having the below operations which translate into the crud operations as mentioned in the interface</p>
  
  <pre><code>GetSettingsForUserIDMatchingSettingName(string userid, string settingname);
  CreateSettingForProfile(string userid, Setting setting);
  Create(string userid, Setting setting);
  Update(string userid, Setting setting); 
  GetAllProfiles();
  GetProfilesMatchingUserID(string userid);
  GetSettingsForUserID(string userid);        
  GetProfilesForUserIDWithSettingName(string userid, string settingname);
  </code></pre>
  
  <p>How to create my specification class or interface so that my specification caters to all the use cases.</p>
  
  <p>I am referring to the below github link to implement but i am lost.</p>
  
  <p><a href="https://github.com/patrikfr/specification/blob/master/specification/src/com/granular8/specification/genericspec/Specification.java" rel="nofollow noreferrer">https://github.com/patrikfr/specification/blob/master/specification/src/com/granular8/specification/genericspec/Specification.java</a></p>
  
  <p>Kindly, help.</p>