Constructor with too many parameters

Last modified: 03 December 2024

Reports constructors whose number of parameters exceeds the specified maximum. Such objects are hard to instantiate, especially if some parameters are optional. Constructors with too many parameters may indicate that refactoring is necessary. Consider applying the builder pattern, for example.

Example:

Configure the inspection:

  • Use the Parameter limit field to specify the maximum allowed number of parameters in a constructor.

  • Use the Ignore constructors with visibility list to specify whether the inspection should ignore constructors with specific visibility.