title: Is it OK to pass parameters to a Factory method?
body: <p>One of the ways to implement Dependency Injection correctly is to separate object creation from business logic.  Typically, this involves using a Factory for object creation.</p>
  <p>Up until this point, I've never seriously considered using a Factory so I apologize if this question seems a little simplistic:</p>
  <p>In all the examples of the Factory Pattern that I've run across, I always see very simple examples that have no parameterization.  For example, here's a Factory stolen from <A HREF="http://misko.hevery.com/" rel="nofollow noreferrer">Misko Hevery's</A> excellent <A HREF="http://misko.hevery.com/2008/07/08/how-to-think-about-the-new-operator/" rel="nofollow noreferrer">How To Think About the &quot;new&quot; Operator</A> article.</p>
  <pre>
  class ApplicationBuilder {
    House build() {
      return new House(new Kitchen(
                 new Sink(),
                 new Dishwasher(),
                 new Refrigerator())
             );
    }
  }
  </pre>
  <p>However, what happens if I want each house that I build to have a name?  Am I still using the Factory pattern if I re-write this code as follows?</p>
  <pre>
  class ApplicationBuilder {
    House build( const std::string & house_name) {
      return new House( house_name,
                        new Kitchen(new Sink(),
                                    new Dishwasher(),
                                    new Refrigerator())
                      );
    }
  }
  </pre>
  <p>Note that my Factory method call has changed from this:</p>
  <pre>
  ApplicationBuilder builder;
  House * my_house = builder.build();</pre>
  <p>To this:</p>
  <pre>
  ApplicationBuilder builder;
  House * my_house = builder.build("Michaels-Treehouse");</pre>
  <p>By the way: I think the concept of separating object instantiation from business logic is great, I'm just trying to figure out how I can apply it to my own situation.  What confuses me is that all the examples I've seen of the Factory pattern never pass any parameters into the build() function.</p>
  <p>To be clear: I don't know the name of the house until the moment before I need to instantiate it.</p>