Key Takeaways

Starting with a well-tested view controller, we were able to change it to the MVP pattern. First, we set up the relationships:

Then we followed this approach:

We did all this with disciplined refactoring, relying on a thorough set of unit tests. The tests check the end result we want, but are ignorant of the UI pattern we use. This allowed us to change from MVC to MVVM to MVP, with only minor changes in test code. In other words, the tests check the behavior, not the implementation.

Here are the manual refactoring moves we discussed in this chapter: