Click here to Skip to main content
15,891,204 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: C# code survey Pin
michaelakin31-Oct-18 4:08
michaelakin31-Oct-18 4:08 
GeneralRe: C# code survey Pin
michaelakin31-Oct-18 4:08
michaelakin31-Oct-18 4:08 
GeneralRe: C# code survey Pin
jhunley31-Oct-18 4:17
jhunley31-Oct-18 4:17 
GeneralRe: C# code survey Pin
michaelakin31-Oct-18 4:29
michaelakin31-Oct-18 4:29 
GeneralRe: C# code survey Pin
jhunley31-Oct-18 5:00
jhunley31-Oct-18 5:00 
GeneralRe: C# code survey Pin
Bruce Patin31-Oct-18 3:44
Bruce Patin31-Oct-18 3:44 
GeneralRe: C# code survey Pin
michaelakin31-Oct-18 4:19
michaelakin31-Oct-18 4:19 
AnswerRe: C# code survey Pin
Leonardo Pessoa31-Oct-18 6:43
Leonardo Pessoa31-Oct-18 6:43 
I believe there are reasons for either style and I don't mean a simple preference by the developer.


The first style allows you to initialise an object with some default values and gradually fill its properties with desired non-default values. Also it allows you to change those values over time to reflect changes in how the class (or another dependent class) should behave. You can see that in any visual component for UWP/WPF/ASP.NET. Meanwhile, the second style creates a kind of immutable object (it can only be read although its properties can still be changed due to internal operations, if any). Changes to this data may not be desired due to e.g. the intended design of the application (or API) or legal reasons.


If you must follow the second style with a class with so many constructor arguments (with which I agree it might be a code smell), I'd recommend creating a Builder for the object. MyFooClass in this example seems to be one which might actually hint at why the guy wanted you to change the code style; perhaps he thought you were trying to create in MyFooClass a Builder for FooDto and wanted you to make it so both classes don't repeat themselves. Anyway, I'd recommend approaching the guy with an open mind to try and understand his motivations for requesting the style change; it may either enhance your knowledge of the application or the guy you're working with.

[UPDATED] Both Dan's or Marc's answers offer a great alternative to avoiding so many arguments on the constructor. I'd also check if you could go either way.
- Leonardo


modified 31-Oct-18 12:49pm.

GeneralRe: C# code survey Pin
Leng Vang31-Oct-18 8:06
Leng Vang31-Oct-18 8:06 
GeneralRe: C# code survey Pin
Super Lloyd31-Oct-18 9:17
Super Lloyd31-Oct-18 9:17 
GeneralRe: C# code survey Pin
Roger House31-Oct-18 14:10
Roger House31-Oct-18 14:10 
GeneralRe: C# code survey Pin
patbob1-Nov-18 5:29
patbob1-Nov-18 5:29 
GeneralI was sent this, and... Pin
OriginalGriff29-Oct-18 21:03
mveOriginalGriff29-Oct-18 21:03 
GeneralRe: I was sent this, and... Pin
Chris Maunder30-Oct-18 3:09
cofounderChris Maunder30-Oct-18 3:09 
GeneralRe: I was sent this, and... Pin
OriginalGriff30-Oct-18 3:19
mveOriginalGriff30-Oct-18 3:19 
GeneralRe: I was sent this, and... Pin
kalberts30-Oct-18 3:43
kalberts30-Oct-18 3:43 
Generalif you are feeling smart today...! Pin
David Crow29-Oct-18 10:34
David Crow29-Oct-18 10:34 
GeneralRe: if you are feeling smart today...! Pin
Kschuler29-Oct-18 10:43
Kschuler29-Oct-18 10:43 
GeneralRe: if you are feeling smart today...! Pin
Sander Rossel29-Oct-18 10:44
professionalSander Rossel29-Oct-18 10:44 
GeneralRe: if you are feeling smart today...! Pin
CodeWraith29-Oct-18 10:46
CodeWraith29-Oct-18 10:46 
GeneralRe: if you are feeling smart today...! Pin
Sander Rossel29-Oct-18 11:35
professionalSander Rossel29-Oct-18 11:35 
GeneralRe: if you are feeling smart today...! Pin
CodeWraith29-Oct-18 11:39
CodeWraith29-Oct-18 11:39 
GeneralRe: if you are feeling smart today...! Pin
OriginalGriff29-Oct-18 12:42
mveOriginalGriff29-Oct-18 12:42 
GeneralRe: if you are feeling smart today...! Pin
CodeWraith29-Oct-18 10:45
CodeWraith29-Oct-18 10:45 
GeneralRe: if you are feeling smart today...! Pin
Marc Clifton29-Oct-18 11:26
mvaMarc Clifton29-Oct-18 11:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.