Chapter 4. Separation of Concerns
“Separation of concerns” ... is what I mean by “focusing one’s attention upon some aspect”: it does not mean ignoring the other aspects, it is just doing justice to the fact that from this aspect’s point of view, the other is irrelevant. It is being one- and multiple-track minded simultaneously.
Edsger Dijkstra, “On the Role of Scientific Thought”
Our source code has grown. Depending on the language, it’s 50–75 lines in one source file. That’s more than a screenful on many display monitors, and certainly more than a printed page in this book.
Before we get to the next feature, we’ll spend some time refactoring our code. That’s the subject of this and the next three chapters.
Test and Production Code
Thus far, we’ve written two different types of code.
-
Code that solves our Money problem. This includes
MoneyandPortfolioand all the behavior therein. We call this production code. -
Code that verifies that the problem is correctly solved. This includes all the tests and the code needed to support these tests. We call this test code.
There are similarities between the two types of code: they are in the same language, we write them in quick succession (through the by now familiar red-green-refactor cycle), and we commit both to our code repository. However, there are a few key differences between the two types of code.
Unidirectional Dependency
Test code has to depend on production code—at least on those parts of production code that it tests. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access