Rule of Three

Sometimes called “Three Strikes and You Refactor”, “1, 2, refactor”, the “Rule of Three” is code refactoring rule of thumb to remove duplication when a piece of code could be replaced by a new procedure.

“Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior” ― Martin Fowler

But introducing abstractions too early is one cause of poor design. It is better to wait until a three times duplication is visible before making an effort to refactor it.