Recently, I was torn up when I tried to write classes regarding the number of requested parameters.
An example of a simple simple constructor:
Burger(bun, meat, cheese, lettuce) this.bun = bun this.meat = meat ...
Vs
Burger(grocery) this.bun = grocery.bun this.meat = grocery.meat ...
Both methods are valid approaches. The first method shows what exactly happens in a hamburger, breaks down the arguments into more general classes, so it reduces cohesion, and it seems to me easier to check, because the graph of objects is simpler.
But the second method is much simpler, cleaner, and perhaps a hamburger may require much more ingredients, then the arguments in the first case can be inflated without any problems.
I would like to know which method would be recommended in such a situation? Go for a cleaner, but more related code, or a more verbose way.
source share