title: How to maintain SRP (Single Responsibility Principle) with multiple dependencies?
body: <p>I am confused in a situation where a class must depend on other factors.</p>
  
  <p>For example</p>
  
  <pre><code>class Storage:
      def __init__(self):
          self.logger = Logger()
          self.client = Elasticsearch()
  
      def index(document):
          try:
              self.client.index(document)
           except ElasticsearchException as e:
               self.logger.error(str(e))
  </code></pre>
  
  <p>Here my class has to have logger and an <code>Elasticsearch</code> object to perform its operations. How can I maintain SRP in this situation where there are possibly two scenarios where my class has to be changed, such as:</p>
  
  <ol>
  <li>I switched to different database</li>
  <li>I switched to different logging library</li>
  </ol>
  
  <p>One could argue that instead of logging here I should let the client class handle the exception. But in a scenario where client is just <strong><code>yield</code>ing</strong> the documents to be inserted and it is accepted to have a failed index operation, the client class doesn't bother about errors. Also, even if I re-throw the exception to client class, the same SRP problem will occur there.</p>
  
  <p>I would appreciate an explanatory answer in my context.</p>