Growing Object-Oriented Software, Guided By Tests (chapter 18)

Feb 21, 22

Use an iterative, agile approach to help guide your design:

The agile approach

State machines appear to be super useful when designing software, leverage them as much as possible.

Write ‘blue sky thinking’ tests to push things forward. We should be writing tests for the system we want, not the system we have. Let the tests guide your design.

Don’t be afraid to create types where there is a need. Usually, they will reveal themselves as you progress through your design. They will give you a name place to hang behaviour on, before passing data around your system.

This encapsulation of data and behaviour will help to stop you from having to follow a chain of method calls through the entire system.

When testing, make sure to distinguish between setup code and code that is asserting the intended behaviour. Don’t mix the two!

We are reminded that the only constant in software development is change, so we must code in a way that leaves us able to adapt to changing requirements.

The authors’ reiterate the benefit of having state-based diagrams and highlight how this can directly map to the tests (and can show when you have covered all the possibilities).

Use techniques like this to augment your test writing process, it will help to give you direction when working with complex systems.

Domain types are better than strings

When passing strings or primitive types through the system, try to think if it would be better to create a new type. Any behaviour can be hung off this new type, and it may express intent better than a simple string or array for example.