Favorite Refactoring Techniques: Extract Functions
Naomi Dennis
Posted on January 9, 2020
The next refactoring technique we'll look at is extracting behavior into functions. Say we have the following example:
SubwayTrain#processStop
has a lot of behavior. The intention could be made clearer by separating each behavior into its own method. The behavior we extract will also become available to other classes that may need it, outside of the context of getting passengers at a subway station.
After extracting the behavior, #processStop
looks like this:
💖 💪 🙅 🚩
Naomi Dennis
Posted on January 9, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.