Skip to main content
11 events
when toggle format what by license comment
Feb 20, 2021 at 22:34 comment added sartoz @Pete Showing the concrete example is complicated. Because what led me to write this question, is a function of a project that I'm working on. The function is receiving 12 parameters for printing a report. As it is a report, the function is very tied to the company's business rule, it would be necessary to have knowledge of the database tables to understand it. So I cannot expose this information. Talking to my supervisor, he told me to create a DTO, I did it the way he asked, but it kept hammering in my head.
Feb 20, 2021 at 22:05 vote accept sartoz
Feb 19, 2021 at 7:55 comment added Pete I might at some point write a "real" answer if I get the time, but I have two points: You phrase this question as how to pass all this information to the function cleanly, but I think you should look at if it is the function itself that needs all this data because it is doing too much? But without a more concrete example, it's difficult to tell. Secondly, the type of object you are referring to, I would call a "Request Object". There are good uses for a such, but I normally only use them at the outer boundaries of the system. That didn't seem to be the case in your scenario.
Feb 19, 2021 at 7:10 comment added slebetman IMO those objects are NOT DTO. They're parameter objects (personally I end the class names with "Param" but that's just me). In some cases you may find yourself passing both a DTO (the data) and a parameter object to a single method call (eg, making API call to Ebay and you need to pass both the product DTO and the request parameters)
Feb 19, 2021 at 5:53 answer added SergeiTonoian timeline score: 0
Feb 18, 2021 at 16:04 answer added JonasH timeline score: 0
Feb 9, 2021 at 16:56 comment added Filip Milovanović More generally, another thing to consider when you have a long parameter list is why your class/method needs all those parameters - maybe it's doing too much; maybe there's an elegant way to split it into two or three more focused objects that are easier to understand/manage, and can work together to achieve the same result.
Feb 9, 2021 at 16:53 comment added Filip Milovanović "to avoid having to keep creating files/classes that only serve to be passed as parameters" - it's a matter of style, but there's really no need to avoid such classes. These classes are in essence part of the interface of the class that takes them as a parameter, and also a chance for you to explicitly name a concept. Also, if you're writing tests, you'll reuse them in a different setting in your test suite. BTW, C# doesn't require you to have a single class per file. Perfectly acceptable to group closely related classes together, and you can also create nested classes.
Feb 9, 2021 at 13:46 answer added Kilian Foth timeline score: 3
Feb 9, 2021 at 12:26 review First posts
Feb 9, 2021 at 12:33
Feb 9, 2021 at 12:22 history asked sartoz CC BY-SA 4.0