Code Smells

Code Smells / Dispensables / Duplicate Code

Duplicate Code code smell icon

Duplicate Code

A Duplicate Code smell represents code in multiple places that is the same or very similar.

If the functionality of some code is shared, there is a good chance that the purpose is also shared, and so the functionality should be implemented in one place and then reused where it is required.

To combine the duplicated code, a superclass may be appropriate, or an additional third class may be the best solution. Where functionality is similar but not the same, generalising the code may be necessary in the new unified code.

Having the same or similar code in multiple places can also lead to Shotgun Surgery.

Left chevron Right chevron

Books about code smells

Learn to write better smelling code.

Refactoring: Improving the Design of Existing Code book cover

Refactoring: Improving the Design of Existing Code

Code smells: A Predictor of Remarkable Quality Improvement book cover

Code smells: A Predictor of Remarkable Quality Improvement

Clean Code: A Handbook of Agile Software Craftsmanship book cover

Clean Code: A Handbook of Agile Software Craftsmanship

I receive a commission on sales made from the above affiliate links.