As I’ve blogged before, a Kata is a practice exercise.  I’m attempting to brainstorm out a kata for each of the main GoF design patterns, partly as a mental exercise, and partly as the first step in producing a course that I can give to developers so that they will truly “get” how design patterns can be used.

Template method is a simple pattern, really.  The idea is that the base class provides code for a method that calls abstract methods to do some of the work.  The concrete children implement only the abstract methods.  Users of the concrete methods call the base class implementation which does all the work.

For a kata to work, I need to create a DLL that behaves in a particular way, and a set of unit tests, all of which fail.  The student is responsible for creating a class or multiple classes in such a way that all unit tests pass and any non-testable constraints (like the choice to use a particular pattern) can be verified.

I’m thinking that the base class should have methods for depth-first-search and breadth-first-search, but should delegate the movement from a node to its child to the concrete object.  That way, a developer who creates a tree structure in memory can use either mechanism to search the tree simply by implementing the code to move from one node to another.

If you can think of a better Kata for Template Method, jump in.