Design patterns·Who calls whom, and when
the same switch on type appeared in four methods, and adding a case meant finding all four.
Replace conditional with polymorphism
Also calledpolymorphism over conditionals, kill the switch statement
The refactoring that moves each branch of a type-based conditional into a method on the corresponding subclass, so dispatch does the branching. It pays off when the same conditional is repeated across several operations; it does not pay off for a single switch in a single place, where a class hierarchy is more machinery than the branch it replaced. Recognising which case you have is the actual skill.