Skip to content

Instantly share code, notes, and snippets.

@tgroshon
Last active November 24, 2021 09:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tgroshon/8715d054b341ed9c2a89f48356829c09 to your computer and use it in GitHub Desktop.
Save tgroshon/8715d054b341ed9c2a89f48356829c09 to your computer and use it in GitHub Desktop.
OOP Code Smells by Martin Fowler and Kent Beck grouped by Mika Mantyla

OOP Code smells

Things that might indicate a problem. RailsConf talk "Get a Whiff of This" by Sandi Metz

  • Couplers: binds objects together

    • feature envy (send more messages to object than to self)
    • inappropriate intimacy (access private methods/data)
    • message chains (law of demeter; too many dots)
    • middle man (sole purpose to forward on calls)
  • Change Preventers: disuade you from changing code

    • divergent change
    • shotgun surgery (changing requires massive, all-at-once change)
    • parallel inheritance hierarchies (manually keep hiearchies in sync)
  • Dispensables: most common OOP pitfalls

    • data class (no behavior/methods)
    • duplicated code
    • speculative generality (support non-existant future features)
    • lazy class (doesn't justify existance)
  • Bloaters: makes code bigger

    • data clumps (things passed together)
    • large class
    • long method
    • long paramater list
    • primitive obsession (branching based on dumb data)
  • Tool Abusers: misusing OOP constructs

    • alternative classes w/ different interfaces
    • refused bequest (refusing to implement super class method)
    • switch statements
    • temporary field

Credits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment