title: Shall I extend the service class or just use an instance of it?
body: <p>There is a <code>StoreService</code> in the project, which provides some methods to read from and write to a remote data store. e.g.</p>
  
  <pre><code>public class StoreService {
      public StoreService(String url, String username, String password) {}
      public void save(String category, String key, String value) {}
      public String read(String category, String key) {}
  }
  </code></pre>
  
  <p>Then I see there is another <code>UserStoreService</code> which is in a sub-module of the project, which extends <code>StoreService</code>:</p>
  
  <pre><code>public class UserStoreService extends StoreService {
      public UserStoreService(String url, String username, String password) {
          super(url, username, password);
      }
      public void saveUserName(String userId, String userName) {
          super.save("user", userId, userName);
      }
      public void getUserName(String userId, String userName) {
          return super.read("user", userId);
      }
  }
  </code></pre>
  
  <p>You can see it just add some methods. Is it good to use <code>extends</code> here? </p>
  
  <p>I can make it without <code>extends</code>:</p>
  
  <pre><code>public class UserStoreService {
      private StoreService storeService;
      public UserStoreService(String url, String username, String password) {
          this.storeService = new StoreService(url, username, password);
      }
      public void saveUserName(String userId, String userName) {
          storeService.save("user", userId, userName);
      }
      public void getUserName(String userId, String userName) {
          return storeService.read("user", userId);
      }
  }
  </code></pre>
  
  <p>But I'm not sure which solution is better, and when should I use <code>extends</code> and when not.</p>