You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use Polymorphism, use OO, use interfaces, use abstract classes, use design patterns.
Use Proper Datastructures and/or Design Patterns
How do we detect bad code?
When you see IFs/Switches and Enums.
When you see duplicated code but just 1-2 things are changing.
When you see a lot of procedural code.
Why Enums Sucks? (Java 8 version)
Enums are not OO, very often lead to procedural code(people need todo IFs and
propagate code to many places rather than center on a class). Enums are not really that different them anemic model, getters/setters and DTO (which force the consumer to do the logic).
Enums are not flexible, you can't extend to do sub-typing. Can't do a proper TypeSystem with them.
Enums has fixed set of values cannot be changed at runtime.
Enums can have awful serialization/deserialization nasty issues, what if you try to load a value from DB is not present on enum?
what happens is a nightmare. (Cannot do tolerant reader easier)
Enums are for limited use cases (fixed, immutable lisr of values i.e days of the week).