Skip to content

In the beer example, why using classes instead of records for DTOs #10811

Answered by murdos
dmurat asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @dmurat,
We're not using records because record create a default public constructor with all fields.

We rather favor the usage of a fluent builder for creating an instance, that will force you to set all required fields, and will guide you so that you don't permute parameters by accident.

While it could be possible to also create a builder with a record too, since the record constructor has to be public, it would allow to bypass construction by builder.

I hope that this is clear enough :)

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by dmurat
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants