Code Smell 23 - Instance Type Checking
7 November, 2022
0
0
0
Contributors
TL;DR: Trust your collaborators. Don't check who they are. Ask them to do instead.
Problems
•
Metamodel interference
•
Solutions
1.
Avoid kind, isKindOf, instance, getClass(), typeOf, etc..
2.
Don't use Reflection and Metaprogramming for Domain Objects.
3.
Replace IFs with polymorphism.
4.
Avoid checking for 'undefined'. Use complete objects, avoid nulls and setters, favor immutability and you will never have undefined and ifs.
Sample Code
Wrong
Right
Detection
Tags
•