2 ms·
“Should” is way too strong. “You should consider” is appropriate. An enum is essentially an encoding over integers. I guess this depends on your programming la
by quickthrower2 5y ago
“Should” is way too strong. “You should consider” is appropriate.
An enum is essentially an encoding over integers. I guess this depends on your programming language, so humour me.
If you have an integer whose meaning is a category (as opposed to a count or measure) - does this need refactoring into classes?
Probably not most of the time.
For example you import a CSV and one of the fields is a categorisation. Let’s say county code. Your code may occasionally care if you are in an EU country.
You could have a class per country and override isEU as needed but this is clumsy and ugly in my opinion.
You’d also need a switch statement, in a factory method to create these from the csv data.
A lot of the time it’s easier to follow code where the switch statement is in its intuitive place.
Highly OO abstracted code can be very hard to reason about too.
- dahfizz 5y ago> Highly OO abstracted code can be very hard to reason about too. Definitely. Coming up with all the right design patterns and abstractions can feel quite clever and satisfying. But when someone else needs to debug that code, having to jump through layers and layers of object, interfaces, factories, etc to find out what a method call is actually doing is a pain.