title: Abstract Factory with parameterized constructors
body: <p>I've heard recently about the Abstract Factory Pattern and have currently some doubts on how to design such pattern when parameterized constructors are needed.<br><br>
  More precisely, from what I understood, one of the main benefits of this Design Pattern
  is to facilitate the code management, since whenever a new type is introduced to the system, one needs to adapt one factory function in which the objects constructors are called.<br><br>
  Most of the examples that I found consider only empty constructors (say default constructors).<br> But, what would happen if one needs to use Parameterized Constructors? Does this design pattern still works?<br>
  Since the parameters may differ in type and quantity between the derived classes, 
  does one need to consider several factory functions?
  Below  I'm giving  an example on what I would like to achieve. Note that for reducing the lines of code, I've only considered one constructor per class that serve both as default and parameterized constructor.</p>
  
  <pre><code>class Shape {
  public:
      Shape(){std::cout &lt;&lt; "Calling Shape Constructor\n";};
      virtual ~Shape(){std::cout &lt;&lt; "Calling Shape Desstructor\n";};
      virtual void draw() const = 0;
      virtual void doSomething1(int) const = 0;
      virtual void doSomething2(int, float) const = 0;
  };
  
  class Rectangle : public Shape {
  public:
      Rectangle(int l = 0, int b = 0 ):l(l),b(b){ std::cout &lt;&lt; "Calling Rectangle Constructor\n"; };
      ~Rectangle(){ std::cout &lt;&lt; "Calling Rectangle Destructor\n\n"; };
      virtual void draw() const{ /* Draw Rectangle */ }; 
      virtual void doSomething1(int) const { /* doSomething1 */};
      virtual void doSomething2(int, float) const { /* doSomething2 */};
  private:
      int l,b;
  };
  
  class Circle : public Shape {
  public:
      Circle(int r = 0):r(r){ std::cout &lt;&lt; "Calling Circle Constructor\n"; };
      ~Circle(){ std::cout &lt;&lt; "Calling Rectangle Destructor\n\n"; };
      virtual void draw() const{ /* Draw Circle*/ }; 
      virtual void doSomething1(int) const { /* doSomething1 */};
      virtual void doSomething2(int, float) const { /* doSomething2 */};
  private:
      int r;
  };
  
  class ShapeFactory{
  
  public:
      ShapeFactory(int = 0, double = 0);
      std::unique_ptr&lt;Shape&gt; CreateShape(const std::string &amp; );
      ~ShapeFactory();
  };
  
  std::unique_ptr&lt;Shape&gt; ShapeFactory::CreateShape(const std::string &amp; type /*, int rad, int side1, int side2, .... */) {
  
      if ( type == "circle" ) return std::unique_ptr&lt;Shape&gt;(new Circle( /* rad */)); // Should call Circle(int rad)!
      if ( type == "rectangle" ) return std::unique_ptr&lt;Shape&gt;(new Rectangle( /* side1, side2 */)); // Should call Rectangle(int, int)!
      // if ( type == "someNewShape") return std::unique_ptr&lt;Shape&gt;(new someNewShape( /* param1, param2, ... */)); // Should call someNewShape(param1, param2)!
      throw std::invalid_argument("MobileFactory: invalid type: " + type);
  }
  </code></pre>
  
  <p>I've also further another doubt. Imagine that because of some needs, I need class members for the "ShapeFactory" class. What I would like to intuitively do, is something like: </p>
  
  <pre><code>std::vector&lt; std::unique_ptr&lt;ShapeFactory2&gt; &gt; mylist;
  mylist.push_back( new ShapeFactory2(CreateShape("circle",radius), param1, param2) );
  mylist.push_back( new ShapeFactory2(CreateShape("rectangle",side1,side2), param1, param2) );
  
  for (std::vector&lt; std::unique_ptr&lt;ShapeFactory2&gt; &gt;::const_iterator it = v.begin(), end = v.end(); it != end; ++it)
  {
      int param1   = it-&gt;param1;
      float param2 = it-&gt;param2;
      it-&gt;doSomething2(param1, param2);
  
      // or equivalently 
      Shape * myShape = *it;
      int param1   = it-&gt;param1;
      float param2 = it-&gt;param2;
      myShape-&gt;doSomething2(param1, param2);
  }
  </code></pre>
  
  <p>How does the 'ShapeFactory' class declaration would change for this specific case? Would I've now a smart_pointer as class member besides param1, param2? If yes, could anyone illustrate how to implement the Constructors/Destructors?<br><br>
  All suggestions/ideas are really welcomed! ;-)</p>