File: TooManyParameters.md

package info (click to toggle)
error-prone-java 2.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 23,204 kB
  • sloc: java: 222,992; xml: 1,319; sh: 25; makefile: 7
file content (13 lines) | stat: -rw-r--r-- 779 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
In
[*Detecting Argument Selection Defects*](https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/46317.pdf)
by Rice et. al., the authors argue that methods should have 5 of fewer
parameters (see section 7.1). APIs with larger than this number often lead to
parameter mismatch bugs (e.g, calling `create(firstName, lastName)` instead of
`create(lastName, firstName)`).

In *Effective Java* (Item 2), Bloch recommends "consider[ing] a builder
[pattern] when faced with many [constructor] parameters". You may consider
encapsulating your parameters into a single
[`@AutoValue`](https://github.com/google/auto/tree/master/value) object, which
is created using an
[AutoValue Builder](https://github.com/google/auto/blob/master/value/userguide/builders.md).