Skip to content

Clean Code Principles

Organize Related Arguments

If a group of arguments seem absolutely necessary in a method, organizing them into their own class will help as long as they are related and cohesive.

Code to Avoid

createUser(String name, String email, int age, String address)

Preferred Code

class UserDetails {
  String name;
  String email;
  int age;
  String address;
}

createUser(UserDetails details)

Benefits:

  • Improves code readability
  • Reduces method complexity
  • Makes it easier to add or remove fields in the future

Released under the MIT License.