title: Python class design for inheritance with varied number of inherited methods
body: <p>I am building a Python API wrapper for a SOAP API.  I need to design a set of API classes which contain a varied number of verb actions (<code>add</code>, <code>get</code>, <code>list</code>, <code>remove</code> etc.).  Additionally, because of the nature of the objects in the SOAP API, these may also contain additional methods from a subset of (<code>sync</code>, <code>options</code>, <code>apply</code>, <code>restart</code> and <code>reset</code>).  Internals of each verb means that very few cases require overriding and can easily be inherited.  My problem is that some endpoints are singletons, or for whatever reason may only support a subset of these methods.  Meaning that:</p>
  
  <p>EndpointA</p>
  
  <ul>
  <li><code>get</code> only</li>
  </ul>
  
  <p>EndpointB</p>
  
  <ul>
  <li><code>add</code>, <code>get</code>, <code>list</code>, <code>remove</code></li>
  <li><code>apply</code> and <code>restart</code></li>
  </ul>
  
  <p>EndpointC</p>
  
  <ul>
  <li><code>add</code> and <code>get</code> only</li>
  </ul>
  
  <p>EndpointD</p>
  
  <ul>
  <li><code>add</code>, <code>get</code>, <code>list</code>, <code>remove</code></li>
  <li><code>apply</code>, <code>restart</code>, <code>reset</code></li>
  </ul>
  
  <p>I have more than 100 endpoints.  Most fit a common theme of:</p>
  
  <ul>
  <li><code>add</code>, <code>get</code>, <code>list</code>, <code>remove</code></li>
  </ul>
  
  <p>There are, however, many exceptions.</p>
  
  <p>In my current design, all endpoints instantiate with <code>Client</code> attribute that controls the SOAP connection, requests and responses on the wire.  I am looking for an approach to flexibly create a class design allowing me to drop in methods without needing to duplicate code or inadvertently inherit methods that an API endpoint doesn't support.  </p>
  
  <p>A flat inheritance is problematic as I don't have enough flexibility for all the permutations for methods.</p>
  
  <pre><code>BaseAPI(object):
  
      def __init___(self, client):
          self.client = client
  
  
  ChildAPI(BaseAPI):
  
      def __init___(self, client):
          super().__init__(client)
  
      def get(self, **kwargs):
          soap_method = methodcaller("".join(["get", self.__class__.__name__]), **kwargs)
          resp = soap_method(self.client.service)
          return resp
  
      def list(self, **kwargs):
          soap_method = methodcaller("".join(["list", self.__class__.__name__]), **kwargs)
          resp = soap_method(self.client.service)
          return stuff
  
      # same for add and remove...
  
  
  EndpointA(BaseAPI):
  
      def __init___(self, client):
          super().__init__(client)
  
      # now i have a problem as i only wanted the get method...
  
  
  EndpointD(BaseAPI):
  
      def __init___(self, client):
          super().__init__(client)
  
      # I have all the methods I wanted...
  </code></pre>
  
  <p>I was thinking about mixins, but as you can see, the verb methods are dependent on the common client.  From my understanding, mixins should only inherit from <code>object</code>.</p>
  
  <p>Can anyone suggest how to lay out my class design to promote re-use as far as possible, and avoid a lack of flexibility?</p>