Use template pattern to reduce duplication
Created by: mattclarke
Pulled the commonality out into a base class as there was a duplication of code and concepts.
Not sure I entirely like it, so I opened the PR to see what people think. If we like it, then I will add the types and improve the names etc.
Worse case, it has been a good way to learn the code