I once explained what refactoring was to a non-programmer. It went like this:
“We software developers (programmers for short) do not only need to write a program that accomplishes a task. That’s the easy part. The difficult part is to change an existing program to adapt to new requirements / problems.
A lot of thought has been put into this problem. Methodologies, advice, tips, books, best-practices arose and continue to arise to address this issue.
Imagine we have code that interacts with external systems. External systems could mean:
- interacting with a database
- interacting with a file-system
- printing something to the console
- interacting with a remote service
- and so on
How do we test a program like this? How do we make sure it does the right thing after we change something in its logic, or its structure, when we add a feafure of fix a bug?
In this post we will look at a general approach to achieve this.