title: Object generator pattern
body: <p>I have a class that represents a pretty complex object. The objects can be created by many ways: incremental building, by parsing text strings in different formats and by analyzing binary files. So far my strategy was as follows:</p>
  
  <ul>
  <li><p>Have the constructor (<code>__init__</code>, in my case) initialize all the internal variables to <code>None</code></p></li>
  <li><p>Supply different member functions to populate the object</p></li>
  <li><p>Have those functions return the new, modified object to the caller so we can do <code>sd = SuperDuper().fromString(s)</code></p></li>
  </ul>
  
  <p>For example:</p>
  
  <pre><code>class SuperDuper:
      def __init__(self):
          self.var1 = None
          self.var2 = None
          self.varN = None
  
      ## Generators
      def fromStringFormat1(self, s):
          #parse the string
          return self 
      def fromStringFormat2(self, s):
          #parse the string
          return self
      def fromAnotherLogic(self, *params):
          #parse params
          return self
      ## Modifiers (for incremental work)
      def addThis(self, p):
          pass
      def addThat(self, p):
          pass
      def removeTheOtherOne(self, p):
          pass
  </code></pre>
  
  <p>The problem is that the class becomes very huge. Unfotunately I am not familiar with OOP pattern designs, but I assume that there is a more ellegant solution for this problem. Is taking the generator functions out of the class (so that <code>fromString(self, s)</code> becomes <code>superDuperFromString(s)</code> a good idea?</p>