httpflow icon indicating copy to clipboard operation
httpflow copied to clipboard

Do C# 9.0 Record Types Make ValueObject redundant?

Open Cowlephant opened this issue 6 years ago • 2 comments

I'm learning about C# 9.0 record type, a little late to the game, and they seem like they accomplish what ValueObject intends to solve.

The only thing it doesn't seem to do, is allow equality comparison when they have properties that are collections. The ValueObject (or at least the version I have) seems to allow for this whereas the record type does not.

Do you have any advice on where ValueObject should be used and should have record as the favored replacement?

Cowlephant avatar Nov 07 '20 05:11 Cowlephant

Even before record types, valueobject's utility is questionable. I agree with your assessment that with C# 9 record types, those should typically be used rather than value objects. Objects that have collection properties usually aren't good candidates for value objects in my experience, anyway. If you have a case to make for one I'd be interested in hearing it.

ardalis avatar Nov 09 '20 15:11 ardalis

I'll defer to your expert judgement on that one. I'll definitely shift to using record for my value objects.

Cowlephant avatar Nov 09 '20 21:11 Cowlephant