S01E09: [TDD πŸ… 8] Establishing a Presentation Layer in Swift

In this episode, we continue the development of the UI as we start implementing the ResultsViewController, a class responsible for showing the result of a finished game.

Unlike the QuestionViewController, we reach a point where we need to deal with more complicated logic for displaying the right information on the screen, such as a score summary and different layouts for correct and wrong answers. It’s important to separate the presentation logic from the ViewController, so it is easier to test, maintain and reuse it. To achieve this separation, we create our first Presentation layer component, the PresentableAnswer struct that holds all necessary information for a View to render the appropriate information.

The Presentation layer does not reference the UI layer, making it reusable for different platforms such as tvOS and macOS.

This modular approach enables us to test-drive the presentation implementation and also develop both layers independently. It accelerates the development cycle and reduces the cost of development and testing. Altering or removing the modules can be done seamlessly since the impact is minimal and, by following the TDD discipline it is also regression-free.

It’s worth mentioning that TDD didn’t lead us to this modular design; however, it encourages us to make those good design decisions along the way. Every time you notice that something is hard to test, you are probably dealing with a complicated design that might require some extra thinking. Simplify it!

Good or bad design is not a product of TDD, rather of us, the developers.

In this episode, we show how TDD helped us decide when it was time to start forming the UI/Presentation separation and when to create types.

As software professionals, we should strive to create solutions that don't tie us down to specific platforms or frameworks. We can start by maximizing the number of decisions not done, leaving options open as much as we can. It’s important to delay decisions to avoid misleading assumptions, allowing the software to grow in a sustainable and controlled manner, with reduced cost for creation and maintenance and without fear of future changes.

Subscribe now to our Youtube channel and catch free new episodes every week and follow along the project's progress on GitHub.