mobile menu icon

An example of introducing symmetry to enable duplication removal

Published by Manuel Rivero on 02/01/2017

Design Patterns, Implementation Patterns, Katas, Learning, Refactoring, Code Smells


Symmetry is a subtle concept that may seem only related to code aesthetics. However, as Kent Beck states in Implementation Patterns,

"...finding and expressing symmetry is a preliminary step to removing duplication. If a similar thought exists in several places in the code, making them symmetrical to each other is a first good step towards unifying them"

In this post we'll look at an example of expressing symmetry as a way to make duplication more visible. This is the initial code of a version of a subset of the Mars Rover kata that Álvaro García and I used in a refactoring workshop some time ago: