As we've seen previously, it is fairly common to need to share code between functions. In the first two examples in this book, we copy-pasted the code that does the text processing. Now, as we move forward and introduce more and more possible inputs, we may want to plug them into a unified processing unit instead of following the error-prone copy-paste process.
A great advantage of encapsulating a common functionality used by the functions in a separate class is the improved testability of the code. The new class will generally have a single responsibility, which can be tested with a suite of unit tests. The test class can rely on Dependency Injection, which is not yet available in function implementation itself. Dependency Injection makes it easier to "mock" any of the external components used in the code. To learn more about Dependency...