Is too many params in a constructor for a factory a code smell?

First of all, I should mention that I don't necessarily think six parameters are too many. But if you insist...

I don't think the problem at all lies in the number of parameters to the constructor.

The builder pattern that others recommend is useful for classes that contain a lot of state. This is rarely the case for a factory. I am instead going to assume that the parameters you are talking about are dependencies on other classes. The real problem is that your factory has too many dependencies - not that its constructor takes too many arguments.

Instead you need to look at design. Why does the factory have so many dependencies? Is it possible to reduce that number somehow? Maybe the objects that the factory creates are themselves too complex?


  • consider grouping your parameters (whatever makes sense) into FactoryConfigurationObject of some kind
  • if that fails, consider using Builder pattern
  • but generally yes, above 3 parameters begins to smell...

This is especially a problem when many of the parameters are optional. In such cases, consider the Builder Pattern.

Also, consider whether your constructor really needs each of the specific classes you're providing. For example, if it needs a URL, then pass it a URL, not a WebPage object that happens to have a URL property. This won't reduce the number of parameters, but it will limit the surface area of external dependencies.

Regarding your update: Mine and @iluxa's responses focus largely on another downside of methods with multiple params, which is that they are hard to read and maintain. The Builder in this context is an alternative to your Factory. See this answer.

The dependency issue can only be answered with another question: does your Factory truly depend on every param? Try to think of ways in which it might not.