Replies: 8 comments
-
Great summary, thank you! As for me, I would agree that IComparable is niche and definitely not needed for everyone. I was also affected by breaking change GetEqualityComponents and this wasn't nice |
Beta Was this translation helpful? Give feedback.
-
Very good recollection of this whole saga with IComparable, thanks. I think the idea with extracting a ComparableValueObject is good. But do we really need to do the same with Entity? Since entities have an Id, they essentially get the comparable behavior for free, unlike value objects. cc people involved in the previous PRs: @SirBuckinghamVI @teheran @robertlarkins |
Beta Was this translation helpful? Give feedback.
-
Thank you both! And that is a good point, I figured I would for consistency but I agree it is probably overkill when only comparing the identifier. Also, @SirBuckinghamVI is actually an old account of mine, so I am good with it 😄 |
Beta Was this translation helpful? Give feedback.
-
Sounds good then. Feel free to submit a PR please. |
Beta Was this translation helpful? Give feedback.
-
Will do! |
Beta Was this translation helpful? Give feedback.
-
This is addressed in PR #552. |
Beta Was this translation helpful? Give feedback.
-
Yep. Sorry again, tough last couple of months. Should be better at replying going forward. Do you think we need |
Beta Was this translation helpful? Give feedback.
-
No worries! Replied on the PR |
Beta Was this translation helpful? Give feedback.
-
Hi all. I think it may be good to remove the comparison logic and IComparable from the base ValueObject, and instead add a derived ComparableValueObject : ValueObject, or similar. I have an overview of my thoughts on this below, and wanted to start a discussion on it.
For some context, I wanted to recap the history of ValueObject's implementation of IComparable. Feel free to let me know if I missed anything here.
I view the overall concept of default ValueObject comparison logic through two lenses: those who need comparison on their derived ValueObjects and those who don't. The result of the changes above can make it much simpler for those who do need comparisons, as logic for it is already included in the base class. However, I think this is at the expense of those who do not need it.
This is largely because requiring all equality components to implement IComparable can be quite a hassle for existing value objects. Updating the types of all equality components in a project to implement IComparable can be a significant overhead, and it might not even be doable. For example, suppose I have a type representing an event on a timeline. It has no identity, just a time interval and an event type. If I wanted to use an Enum for the event type and NodaTime.Interval for the time interval, I currently could not make my event type a ValueObject, as Interval does not implement IComparable.
To that end, I propose splitting out a derived ComparableValueObject : ValueObject, IComparable and removing IComparable and comparison logic from the base ValueObject. This could be done for Entity as well. This approach would provide the convenience of default comparison logic and IComparable implementation for those who do want comparisons, without burdening those who don’t want comparisons as described above. This would be a breaking change (but requiring IComparable for all equality components was too). I also think this could be an interface segregation improvement that helps avoid having to try to balance competing needs of those who do and don't want default comparions in the future.
I would be happy to make a PR to implement this. Let me know if you would like me to start one to further show what I mean here.
Beta Was this translation helpful? Give feedback.
All reactions