Too many parameters is considered bad practice and should be avoided where possible.
The reason is that if you have the following function:
public void addUser(String username, String firstname, String lastname)
It is very easy to confuse the parameters when calling the functions (was the first parameter firstname or username?).
addUser("johnd", "John", "Doe");
To solve this, it is always best to group parameters when you get too many. For instance into a class called Name
with a member firstname
and lastname
.
Name name = new Name("John", "Doe");
addUser("johnd", name);
This problem also arises with fewer parameters (as in my example) but with more, especially when there are many of the same type, it gets gradually worse.