Agile FAQs
  About   Slides   Home  

 
Managed Chaos
Naresh Jain’s Random Thoughts on Software Development and Adventure Sports
     
`
 
Discovering...
Industrial Logic

Microblog Feed
    Previous Feeds...
    Recent Thoughts

    Recent Comments
    Categories
    Archives
    October 2009
    M T W T F S S
    « Sep   Nov »
     1234
    567891011
    12131415161718
    19202122232425
    262728293031  
    RSS Feed
    Add to Technorati Favorites

    Primitive Obsession

    When you smell complexity and lack of clarity in the air, look around, you’ll find your code swimming in a (smelly) soup of primitives (low level data-types, functions and language components). Unable to bare the stink, your code is screaming and screeching, asking you to rescue it.

    This is my friend, primitive obsession, the stinkiest code smell. You can rescue your code (yes we can) by creating higher level abstractions (functions, data types, objects) and giving some sense to this anarchy.

    Primitive Obsession

    Primitive Obsession is about lack of abstractions. In the OO world, Methods, Objects, Packages/Namespaces are ways of creating abstraction. Similarly functions, procedures, modules, etc are also valid ways of creating abstractions.

    Adding more objects does not always lead to better abstraction. Sometimes removing objects is more useful.

    There are many different refactorings that can be used as a remedies:

    • Extract Class
    • Replace Data Value with Object
    • Replace Type Code with Class
    • Introduce Parameter Object
    • Replace Array with Object

    One of my favorite example of Primitive Obsession (before and after).

    • Share/Bookmark
    blog comments powered by Disqus
        Licensed under
    Creative Commons License
    Design by vikivix