I see 2 more often but with the children being data classes. But in general option 2 gives you more flexibility on how the children need to implement it, but is more verbose with the override.
y
y
04/21/2025, 4:30 PM
indeed 2 seems easier to write but the verbosity annoys me
y
04/21/2025, 4:37 PM
naively this seems like a case where only one syntax should been allowed
m
Michael Krussel
04/21/2025, 5:54 PM
There are differences, so both do slightly different things. If the field is nullable, and abstract property in the base makes it so you cannot smart cast after a null check. That's one reason to prefer option 1 over option 2.