When you face the matter of writing duplicated code, an idea generally rises about how to not waste time.
In strongly typed coding languages a simple mechanism exists, aiding the coder to solve the problem.
The so called Template.
They are designed so that classes and functions able to work with generic types, giving them the possibility to operate on different data types without the need of rewriting code for each of them.
Maybe you've just thought about the concept key: the abstraction.
Indeed we're dealing with it in the sense described above: a template is a try to avoid useless repeating code writing, and to do this we're forced to find a more general way than the direct and boring one.