Java – too much parameter code in a factory constructor?
I have a factory class that currently has six parameters in its constructor. I just need to add another one
Usually, it screams at me, "Hey, your class has too much dependence, so it's too much!"
However, since this class is a strict factory, is it really so? Should I care about more and more dependencies? If so, what policy refactoring should I consider?
Update: I've considered the architect model, but isn't it too much for a factory?
That is, widgetfactorybuilder, which builds a factory for building widgets
In addition, I don't understand how the builder really alleviates my dependencies - it just moves them from constructors to methods - which seems more confusing - but this may be due to how to apply the builder pattern in this case
Solution
First of all, I should mention that I don't necessarily think there are too many six parameters But if you insist
I don't think the problem is the number of arguments to the constructor
Other suggested builder patterns are useful for classes that contain a large number of states This rarely happens in factories Instead, I think the parameters you're talking about depend on other classes The real problem is that your factory has too many dependencies - not that its constructor needs too many parameters
Instead, you need to look at the design Why are factories so dependent? Is it possible to reduce this figure? Maybe the objects created by the factory are too complex?