Refactoring the Nested Conditionals code smell

Nested conditionals are a code smell because they make the code harder to understand. They tend to grow more and more complicated over time because developers will keep adding conditions and more levels of nesting. The deeper the nesting, the more time it’ll eventually take to refactor it. Code Smell: Nested conditionals.Definition: A conditional block … Read more

Refactoring the Switch Statement code smell

The Switch Statement code smell refers to using switch statements with a type code to get different behavior or data instead of using subclasses and polymorphism. In general, it looks like this: This switch(typeCode) structure is typically spread throughout many methods. This makes the code difficult to extend, and violates the Open-Closed Principle. This principle … Read more

Primitive Obsession code smell

The primitive obsession code smell means you’re using primitive types (ex: string, int) excessively instead of encapsulating them in objects. This leads to sloppy code that’s error prone, such as when you have very long parameter lists full of primitives. I’ll show an example of this problem and how to fix it. Here’s a simple … Read more

Refactoring the Large Class code smell

The Large Class code smells refers to a class that has too many responsibilities. It’s doing too much. Ideally a class should only have one responsibility (Single Responsibility Principle). Code Smell: Large Class Definition: A class has too many responsibilities. Solution: Large Class code smell example Here’s an example of the Large Class code smell … Read more

Refactoring the Long Method code smell

In this article I’ll be walking through an example of how to refactor the Long Method code smell. Code Smell: Long Method Definition: A method has too many lines of code, making it hard to understand. Solution: Long Method code smell example Here’s an example of the Long Method code smell (source: GildedRose Refactoring Kata). … Read more