Trisha Shetty (Editor)

Design smell

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

Does your design smell


In computer programming, design smells are "structures in the design that indicate violation of fundamental design principles and negatively impact design quality". The origin of the term "design smell" can be traced to the term "code smell" which was featured in the book Refactoring: Improving the Design of Existing Code by Martin Fowler.

Contents

Different authors have defined the word "smell" in different ways:

  • N. Moha et al.: "Code and design smells are poor solutions to recurring implementation and design problems."
  • R. C. Martin: "Design smells are the odors of rotting software."
  • Fowler: "Smells are certain structures in the code that suggest (sometimes they scream for) the possibility of refactoring."
  • Design smells indicate the accumulated design debt (one of the prominent dimensions of technical debt). Bugs or unimplemented features are not accounted as design smells. Design smells arise from the poor design decisions that make the design fragile and difficult to maintain. It is a good practice to identify design smells in a software system and apply appropriate refactoring to eliminate it to avoid accumulation of technical debt.

    The context (characterized by various factors such as the problem at hand, design eco-system, and platform) plays an important role to decide whether a certain structure or decision should be considered as a design smell. Many a times, it is appropriate to live with design smells due to constraints imposed by the context.

    Does your design smell


    Common design smells

  • Missing abstraction when clumps of data or encoded strings are used instead of creating an abstraction. Also known as "primitive obsession" and "data clumps".
  • Multifaceted abstraction when an abstraction has multiple responsibilities assigned to it. Also known as "conceptualization abuse".
  • Duplicate abstraction when two or more abstractions have identical names or implementation or both. Also known as "alternative classes with different interfaces" and "duplicate design artifacts".
  • Deficient encapsulation when the declared accessibility of one or more members of an abstraction is more permissive than actually required.
  • Unexploited encapsulation when client code uses explicit type checks (using chained if-else or switch statements that check for the type of the object) instead of exploiting the variation in types already encapsulated within a hierarchy.
  • Broken modularization when data and/or methods that ideally should have been localized into a single abstraction are separated and spread across multiple abstractions.
  • Insufficient modularization when an abstraction exists that has not been completely decomposed, and a further decomposition could reduce its size, implementation complexity, or both.
  • Cyclically-dependent modularization when two or more abstractions depend on each other directly or indirectly (creating a tight coupling between the abstractions). Also known as "cyclic dependencies".
  • Unfactored hierarchy when there is unnecessary duplication among types in a hierarchy.
  • Broken hierarchy when a supertype and its subtype conceptually do not share an “IS-A” relationship resulting in broken substitutability. Also known as "inappropriate use of inheritance" and "misapplying IS A".
  • Cyclic hierarchy when a supertype in a hierarchy depends on any of its subtypes. Also known as "inheritance/reference cycles".
  • References

    Design smell Wikipedia