title: Interface segregation and single responsibility principle woes
body: <p>I'm trying to follow the <strong>Interface Segregation</strong> and <strong>Single Responsibility</strong> principles however I'm getting confused as to how to bring it all together.</p>
  
  <p>Here I have an example of a few interfaces I have split up into smaller, more directed interfaces:</p>
  
  <pre><code>public interface IDataRead
  {
      TModel Get&lt;TModel&gt;(int id);
  }
  
  public interface IDataWrite
  {
      void Save&lt;TModel&gt;(TModel model);
  }
  
  public interface IDataDelete
  {        
      void Delete&lt;TModel&gt;(int id);
      void Delete&lt;TModel&gt;(TModel model);
  }
  </code></pre>
  
  <p>I have simplified it slightly (there were some <code>where</code> clauses that hindered readability).</p>
  
  <p>Currently I am using <strong>SQLite</strong>, however, the beauty of this pattern is that it will hopefully give me the opportunity to be more adaptable to change should I choose a different data storage method, like <strong>Azure</strong> for example.</p>
  
  <p>Now, I have an implementation for each of these interfaces, here's a simplified example of each one:</p>
  
  <pre><code>public class DataDeleterSQLite : IDataDelete
  {
      SQLiteConnection _Connection;
  
      public DataDeleterSQLite(SQLiteConnection connection) { ... }
  
      public void Delete&lt;TModel&gt;(TModel model) { ... }
  }
  
  ... 
  
  public class DataReaderSQLite : IDataRead
  {
      SQLiteConnection _Connection;
  
      public DataReaderSQLite(SQLiteConnection connection) { ... }
  
      public TModel Get&lt;TModel&gt;(int id) { ... }
  }
  
  // You get the idea.
  </code></pre>
  
  <p>Now, I'm having a problem bringing it all together, I'm certain the general idea is to create a <code>Database</code> class which uses <strong>interfaces</strong> as opposed to the classes (the real implementation). So, I came up with something like this:</p>
  
  <pre><code>public class Database
  {
      IDataDelete _Deleter;
      ...
  
      //Injecting the interfaces to make use of Dependency Injection.
      public Database(IDataRead reader, IDataWrite writer, IDataDelete deleter) { ... }
  }
  </code></pre>
  
  <p>The question here is how should I expose the <code>IDataRead</code>, <code>IDataWrite</code>, and <code>IDataDelete</code> interfaces to the client? Should I rewrite the methods to redirect to the interface? Like this:</p>
  
  <pre><code>//This feels like I'm just repeating a load of work.
  public void Delete&lt;TModel&gt;(TModel model)
  {
      _Deleter.Delete&lt;TModel&gt;(model);
  }
  </code></pre>
  
  <p>Highlighting my comment, this looks a bit stupid, I went to a lot of trouble to separate the classes into nice, separated implementations and now I'm bring it all back together in one mega-class.</p>
  
  <p>I could expose the interfaces as properties, like this:</p>
  
  <pre><code>public IDataDelete Deleter { get; private set; }
  </code></pre>
  
  <p>This feels a little bit better, however, the client shouldn't be expected to have to go through the hassle of <em>deciding</em> which interface they need to use.</p>
  
  <p>Am I completely missing the point here? Help!</p>