4 Make type codes work
This chapter covers
- Eliminating early binding with Never use
if
withelse
and Never useswitch
- Removing
if
statements with Replace type code with classes and Push code into classes - Removing bad generalization with Specialize method
- Preventing coupling with Only inherit from interfaces
- Removing methods with Inline method and Try delete then compile
At the end of the last chapter, we had just introduced a handleInput
function that we could not use Extract method (P3.2.1) on because we did not want to break up the else
if
chain. Unfortunately, handleInput
is not compliant with our fundamental Five lines (R3.1.1) rule, so we cannot leave it as is.
Here’s the function.
function handleInput(input: Input) ...
Get Five Lines of Code now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.