Reputation: 2508
I would like to know which of these options is better in terms of clean (Java) code:
MyClass myObject = new MyClass(
getParameter1(...),
getParameter2(...),
getParameter3(...)
);
or this one:
String param1 = getParameter1(...);
String param2 = getParameter2(...);
String param3 = getParameter3(...);
MyClass myObject = new MyClass(param1, param2, param3);
Upvotes: 0
Views: 1058
Reputation: 11
I think it is a duplication of: Getter-Setter and private variables
Clean code does tell you to use getters and setters.
To give you the proper answer, you should describe the scenario.
Upvotes: 0
Reputation: 2038
I'd prefer to use the first one. Cause with the second one you have 3 extra variables that are not used anymore.
Upvotes: 2