1

So there is some kind of a rule for clean code "No more then 3/4 parametrs to method".

Am curious about should I follow this rule for private methods, method which are disigned to use by other function and not called by user. Or I can pass more then 3/4 parametrs to private methods?

0

2 Answers 2

2

Having clean and easy to use classes is not only necessary for the public API.
Having internal code hard to read and use is not acceptable.

It results to an unbalanced quality design : clean public API design but lower quality in implementation.
While the implementation is as much important to get a good software.

Or I can pass more then 3/4 parametrs to private methods?

You should rather provide a custom class as parameter that holds information you want to pass as individual parameters.

0

Obviously your code is more readable with 3 or 4 arguments rather than 7 or 8, though there are some things you can consider.

If some of the arguments are closely related you can create a placeholder class. For example rather than arguments (int age, String firstName, String lastName) you could use an argument (Person person).

Another case is where the arguments are all of the same type. In this case you can use a varargs and the type signature will look like Type.... varags documentation.

Whilst there is no hard and fast "rule", use your best judgement and think about the readability and maintainability of your code.

Not the answer you're looking for? Browse other questions tagged or ask your own question.