Catalog of Refactoring

Code Smells

  • What? How can code “smell”??\
  • Well it doesn’t have a nose… but it definitely can stink!

{width=“160” height=“280” srcset=“/images/refactoring/content/catalog/bloaters-2x.png?id=21e2800a3c877cc37b95103bcf6ec5df 2x”}

Bloaters

Bloaters are code, methods and classes that have increased to such gargantuan proportions that they are hard to work with. Usually these smells do not crop up right away, rather they accumulate over time as the program evolves (and especially when nobody makes an effort to eradicate them).

<!-- -->
<!-- -->

{width=“160” height=“280” srcset=“/images/refactoring/content/catalog/oo-abusers-2x.png?id=d42468d27ca548c870a47b2ed08c0a16 2x”}

Object-Orientation Abusers {#oo-abusers}

All these smells are incomplete or incorrect application of object-oriented programming principles.

<!-- -->
<!-- -->

{width=“160” height=“280” srcset=“/images/refactoring/content/catalog/change-preventers-2x.png?id=94d4444b1a3414ac3704f4ab53062f08 2x”}

Change Preventers

These smells mean that if you need to change something in one place in your code, you have to make many changes in other places too. Program development becomes much more complicated and expensive as a result.

<!-- -->
<!-- -->

{width=“160” height=“280” srcset=“/images/refactoring/content/catalog/dispensables-2x.png?id=a316a726f68f8778cdfd38e850d00b8b 2x”}

Dispensables

A dispensable is something pointless and unneeded whose absence would make the code cleaner, more efficient and easier to understand.

<!-- -->
<!-- -->

{width=“160” height=“280” srcset=“/images/refactoring/content/catalog/couplers-2x.png?id=86e33d80273d564bd4d48a554167a7c9 2x”}

Couplers

All the smells in this group contribute to excessive coupling between classes or show what happens if coupling is replaced by excessive delegation.

<!-- -->
<!-- -->

Refactoring Techniques {#refactoring .h1}

{width=“160” height=“280” srcset=“/images/refactoring/content/catalog/composing-methods-2x.png?id=75620eee35ec53ff9e21955cba2c70c9 2x”}

Composing Methods

Much of refactoring is devoted to correctly composing methods. In most cases, excessively long methods are the root of all evil. The vagaries of code inside these methods conceal the execution logic and make the method extremely hard to understand---and even harder to change.

The refactoring techniques in this group streamline methods, remove code duplication, and pave the way for future improvements.

<!-- -->
<!-- -->

{width=“160” height=“280” srcset=“/images/refactoring/content/catalog/moving-features-between-objects-2x.png?id=5503a838a78b344754e92cd116207d96 2x”}

Moving Features between Objects

Even if you have distributed functionality among different classes in a less-than-perfect way, there is still hope.

These refactoring techniques show how to safely move functionality between classes, create new classes, and hide implementation details from public access.

<!-- -->
<!-- -->

{width=“160” height=“280” srcset=“/images/refactoring/content/catalog/organizing-data-2x.png?id=881db3197ef8ea87bd55320073462caa 2x”}

Organizing Data

These refactoring techniques help with data handling, replacing primitives with rich class functionality. Another important result is untangling of class associations, which makes classes more portable and reusable.

<!-- -->
<!-- -->

{width=“160” height=“280” srcset=“/images/refactoring/content/catalog/simplifying-conditional-expressions-2x.png?id=a6ffc35feb77eac6108ee31655ae92d1 2x”}

Simplifying Conditional Expressions

Conditionals tend to get more and more complicated in their logic over time, and there are yet more techniques to combat this as well.

<!-- -->
<!-- -->

{width=“160” height=“280” srcset=“/images/refactoring/content/catalog/simplifying-method-calls-2x.png?id=075a4082f9a85d01391184efa3c8f1a1 2x”}

Simplifying Method Calls

These techniques make method calls simpler and easier to understand. This, in turn, simplifies the interfaces for interaction between classes.

<!-- -->
<!-- -->

{width=“160” height=“280” srcset=“/images/refactoring/content/catalog/dealing-with-generalization-2x.png?id=5187a4b8d010877a25761926c2f24a3c 2x”}

Dealing with Generalization

Abstraction has its own group of refactoring techniques, primarily associated with moving functionality along the class inheritance hierarchy, creating new classes and interfaces, and replacing inheritance with delegation and vice versa.

<!-- -->
<!-- -->

Refactoring.Guru{width=“200” height=“241” loading=“lazy” srcset=“/images/content-public/logos/logo-new-2x.png?id=3bc33294e095bab1d6fe9ae421d07837 2x”}{.menu-brand}

Log in Contact us{.userecho-public rel=“nofollow”}

Refactoring.Guru{srcset=“/images/content-public/logos/logo-new-mobile-2x.png?id=7ad5648bfd86ae2e8524147a72877c64 2x”}{.navigation-brand}

Shop Now!{.btn .btn-md .btn-primary .btn-featured}

  • [English]{.caption .d-none .d-lg-inline-block}

[English](https://refactoring.guru/refactoring/catalog "English"){.dropdown-item
.locale-link .active locale="en"}
[Español](https://refactoring.guru/es/refactoring/catalog "Español"){.dropdown-item
.locale-link locale="es"}
[Français](https://refactoring.guru/fr/refactoring/catalog "Français"){.dropdown-item
.locale-link locale="fr"}
[日本語](https://refactoring.guru/ja/refactoring/catalog "日本語"){.dropdown-item
.locale-link locale="ja"}
[한국어](https://refactoring.guru/ko/refactoring/catalog "한국어"){.dropdown-item
.locale-link locale="ko"}
[Polski](https://refactoring.guru/pl/refactoring/catalog "Polski"){.dropdown-item
.locale-link locale="pl"} [Português
Brasileiro](https://refactoring.guru/pt-br/refactoring/catalog "Português Brasileiro"){.dropdown-item
.locale-link locale="pt-br"}
[Русский](https://refactoring.guru/ru/refactoring/catalog "Русский"){.dropdown-item
.locale-link locale="ru"}
[Українська](https://refactoring.guru/uk/refactoring/catalog "Українська"){.dropdown-item
.locale-link locale="uk"}
[中文](https://refactoringguru.cn/refactoring/catalog "中文"){.dropdown-item
.locale-link locale="zh"}

2014-2023 Refactoring.Guru. [All rights reserved.]{style=“white-space: nowrap”}
Illustrations by [Dmitry Zhart]{style=“white-space: nowrap”}{rel=“nofollow”}