I like working in languages with static types, because I like using types as a tool for designing an API before I start coding it.
I also like TDD, because it helps me concentrate on working in small steps to ensure I get consistent results.
But when I combine the two approaches, I often have this problem: I design the type of an API, but before I write unit tests for part of the functionality I find I must implement it because otherwise the compiler complains about the methods being incorrectly typed. For example, in a Java project, I have the following class:
public class TransformedModelObserver<O,S>
private O sourceModel;
private Function<O,S> transform;
// note: a ChangeNotification<S> is a class that can only be constructed with a non-null instance of S
private Consumer<ChangeNotification<S>> receiver;
/** Should call the receiver if and only if the source model change
* is visible in the transformed model.
public void notifySourceModelChanged ()
I can simplify the test by using an identity function for the transform, which would allow for an easy first step, but the compiler complains if I don't call it anyway. So how would I work to implement this method in small test-driven steps in this scenario?