Navs
Code Smells Catalog
Lazy Element

Last Revision — April 19, 2022

1 Min Read


  • Also Known As

    Lazy Class

  • Obstruction

    Dispensables

  • Occurrence

    Unnecessary Complexity

  • Expanse

    Between Classes

  • Related Smells

    - Dubious Abstraction (family)
    - Speculative Generality (caused)
    - Primitive Obsession (antagonistic)

  • History

    Martin Fowler in book (2018): "Refactoring: Improving the Design of Existing Code (3rd Edition)"

    Martin Fowler in book (1999): "Refactoring: Improving the Design of Existing Code"

Lazy Element

A Lazy Element is an element that does not do enough. If a method, variable, or class does not do enough to pay for itself (for increased complexity of the project), it should be combined into another entity.

Causation

This smell can happen due to the aggressive refactorization process in which the functionality of a class was truncated. It can also occur due to the unnecessary pre-planning - Speculative Generality - developer made it in anticipation of a future need that never eventuates.

Problems

Increased Complexity

Projects complexity increases with the number of entities.

Example

Smelly

class Strength:
    value: int

class Person:
    health: int
    intelligence: int
    strength: Strength

Solution

class Person:
    health: int
    intelligence: int
    strength: int

Refactoring:

  • Inline Class
  • Inline Function
  • Collapse Hierarchy

Sources
  • [Origin] - Martin Fowler, "Refactoring: Improving the Design of Existing Code" (1999)