vkhorikov / DddInAction

Source code for the DDD in Practice Pluralsight course
https://www.pluralsight.com/courses/domain-driven-design-in-practice
586 stars 154 forks source link

== in referece type violates expectation #6

Closed monrealis closed 3 years ago

monrealis commented 3 years ago

https://github.com/vkhorikov/CSharpFunctionalExtensions/blob/98dc557a017c00fb66c4cfb19a5aee6c3b8abc03/CSharpFunctionalExtensions/ValueObject/ValueObject.cs#L143 this violates https://rules.sonarsource.com/csharp/RSPEC-3875. I am not sure whether I agree with SonarQube, but could you give your view?

vkhorikov commented 3 years ago

I disagree with this guideline. The equality behavior is domain-specific; the == operation is part of that behavior and should be consistent with Equals et al. The internals of that operator are an implementation detail which depends on whether the class is an entity or a value object.

monrealis commented 3 years ago

Thanks! It is written that implementing IComparable or IEquatable (like String does) would avoid this code smell, as they call it.