From b70884d20bceb5da4be39cef1dacb02a75c838ba Mon Sep 17 00:00:00 2001 From: Ioannis Brant-Ioannidis <72696535+gbrandtio@users.noreply.github.com> Date: Sat, 25 Mar 2023 14:18:12 +0400 Subject: [PATCH] Adding recommendation for 4 or fewer constructor parameters Adding recommendation for 4 or fewer constructor parameters and an alternative of using the Builder Creational Design pattern if the use case is such that is required. --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index c6d7c18..de280ff 100644 --- a/README.md +++ b/README.md @@ -1468,6 +1468,14 @@ class Dashboard { **[⬆ back to top](#table-of-contents)** +### Class constructor arguments (4 or fewer) + +Having constructors with a vast amount of parameters can lead to chaotic dependencies or result to very complex client code that would be required in order to build all of these parameters. The recommendation is to have constructors with 4 or fewer arguments, as humans tend to be able to hold 4 things in their head at once *(Susan Weinschenk, 100 Things Every Designer Needs to Know about People, 48)*. + +If the use case is such that your object is complex enough to possibly require more than 4 constructor parameters, evaluate using the *[Builder](https://refactoring.guru/design-patterns/builder)* Creational Design Pattern instead. + +**[⬆ back to top](#table-of-contents)** + ### High cohesion and low coupling Cohesion defines the degree to which class members are related to each other. Ideally, all fields within a class should be used by each method.