Every piece of knowledge must have a single, unambiguous,
authoritative representation within a system.
Following this principle is one of the best ways to prevent bugs and
move faster. Every duplicated piece of knowledge is a bug waiting to
happen. Many development techniques are really just ways to prevent and
eliminate duplication, and many smells are just ways to detect existing
When knowledge is duplicated, changing it means making the same
change in several places. Leaving duplication introduces a risk that the
various duplicate implementations will slowly diverge, making them
harder to merge and making it more likely that a bug remains in one or
more incarnations after being fixed.
Duplication leads to frustration and paranoia. Rampant duplication is
a common reason that developers reach for a grand rewrite.
Feature envy caused by
leaking internal knowledge of a class that can be encapsulated and
Making behavior easy to reuse is essential to avoiding duplication.
Developers won’t be tempted to copy and paste something that’s easy to
reuse through a small, easy to understand class or method. You can use
these solutions to make knowledge easier to reuse:
Applying these techniques before duplication occurs will make it less
likely that duplication will occur. To effectively prevent duplication,
make knowledge easier to reuse by keeping classes small and focused.