When starting to write a new class, struct, or other type, we most
often have a very specific goal or use case in mind. We might need a
new model to represent some data that we’re working with, or we
might want to encapsulate a piece of logic that’s tailored for a new
feature that we’re building.
However, over time, we quite often find ourselves wanting to use a
highly similar version of that same type or logic, but for something
entirely different. We might want to reuse an existing model, but
handle it in a slightly different way — or we could be looking to
accomplish a task that’s very similar to something we’ve already
solved, but with a different type of result.
The question then becomes — how to take our existing code, and
refactor it to make it more generic and reusable — without ending up
with something messy or unfocused. This week, let’s take a look at a
technique for doing just that — that involves making certain types