4 ms·
I'm also usually pro enum and against inheritance. I find inheritance is harder to read when you jump into a codebase. The expression problem of course is to be
by carlmr 8y ago
I'm also usually pro enum and against inheritance. I find inheritance is harder to read when you jump into a codebase. The expression problem of course is to be considered.
Many languages now also have discriminated unions (enums with data), like F# and Rust, which make enum the better choice in more cases.
- tigershark 8y agoIt always depends on the language that you are using. In c#, for simple cases, enums are perfect, but otherwise you should switch to classes hierarchies. In Java you can use them in more complex cases because you can encode data quite easily. If the amount of data encoded is becoming too much (let’s say more than a couple/three fields per case) than you should switch to classes. In F# you can use a combination of sum and product types and have a happy life with automatic deconstruction and a somehow less happy one with lenses/optics.