-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Refactoring in Java
By :

Let’s start with what Martin Fowler calls the stink parade (I can’t help but mention it because the term cracks me up) with duplicated code. Duplicated code is intuitively a bad smell, and our software engineer instincts will soon learn to reject it as something that harms us. Let’s try to list a few reasons why duplicated code is harmful to the health of our code bases.
Clearly, copy-pasting code is the first thing to avoid, at least in 99% of cases. Taking a piece of code from one class and using it exactly as it is in another is easily avoidable. By pausing for a moment to reflect, it’s highly likely that we can extract a method to use instead of the duplicated code. Centralizing the code in this way ensures better code maintainability. Just think about how nightmarish it would be to maintain (e.g., fixing a bug in) every single piece of copy-pasted code scattered throughout the code base (and the scariest part is that the developers...