$30 off During Our Annual Pro Sale. View Details »

Does Your Architecture Smell?

Does Your Architecture Smell?

Is the quality of your software architecture good? Does it allow you to introduce changes easily? Is it easy enough to understand and explain? To answer these questions and to know their underlying reasons, one needs to know the issues, or more specifically smells in this context, that may occur in a software at architecture granularity. Architecture smells impair quality of the software and make the software hard to maintain and evolve. In this talk, I present seven architecture smells including Feature concentration, God component, Cyclic dependency, Scattered Functionality, and Dense Structure along with their real-world examples. Further, I discuss their impact on various dimensions of software development and propose some pragmatic strategies to avoid, detect, refactor, and manage them.

Tushar Sharma

August 10, 2018
Tweet

More Decks by Tushar Sharma

Other Decks in Programming

Transcript

  1. Does Your Architecture Smell?
    Tushar Sharma

    View Slide

  2. Architecture smells
    Why to care?
    Types and granularities
    Examples
    How to detect
    Smells
    How to avoid

    View Slide

  3. http://www.tusharma.in

    View Slide

  4. • Continuing Growth
    • All in-use software systems will grow
    • Increasing Complexity
    • As a software system evolves, the complexity increases unless efforts are
    made to contain the complexity
    • Declining Quality
    • The quality of the software will decline unless it is rigorously maintained
    Lehman’s laws of software evolution

    View Slide

  5. Evolution of JUnit
    3.7 4.0
    4.5 4.11

    View Slide

  6. Which one is easy to work with?

    View Slide

  7. Code Quality: Why to care?
    Impacted Quality
    • Changeability
    • Understandability
    • Extensibility
    • …
    Product
    Quality
    Code/
    Design
    Quality
    Quality
    issues or
    Smells
    • Time to market
    • Reliability: Impacted by
    poor understandability
    • …
    Indicators
    • Rigidity & Fragility
    • Immobility & Opacity
    • Needless complexity
    • Needless repetition
    • …
    Productivity

    View Slide

  8. 8

    View Slide

  9. “Jugaad is a colloquial Hindi word that can mean an
    innovative fix or a simple work-around, used for solutions
    that bend rules, or a resource that can be used as such,
    or a person who can solve a complicated issue.”
    … a work-around or hack
    जुगाड़
    9
    “Jugaad”

    View Slide

  10. 10
    “Jugaad”

    View Slide

  11. “Jugaad”
    11

    View Slide

  12. “Jugaad”
    12

    View Slide

  13. “Jugaad”
    13

    View Slide

  14. “Jugaad”
    14

    View Slide

  15. Smells are Jugaads in software
    15

    View Slide

  16. View Slide

  17. What is a smell?
    …certain structures in the code that
    suggest (sometimes they scream for) the
    possibility of refactoring.
    - Kent Beck
    20 Definitions of smells: http://www.tusharma.in/smells/smellDefs.html

    View Slide

  18. Types of smells
    • Code smells
    • Implementation smells
    • Architecture smells
    • Design smells
    • Test smells
    • Performance smells
    • Configuration smells
    • Database smells
    • Models smells
    • Usability smells
    • Web smells
    • …

    View Slide

  19. Smells: Types
    http://www.tusharma.in/smells/

    View Slide

  20. Granularity of code smells
    - Implementation
    - Design
    - Architecture

    View Slide

  21. Implementation smells

    View Slide

  22. Design Smells

    View Slide

  23. Architecture Smells

    View Slide

  24. Architecture smells: examples

    View Slide

  25. Demo
    http://www.designite-tools.com

    View Slide

  26. Designite is a software design quality
    assessment tool for C#.
    Key features
    • Detects 7 architecture smells
    • Detects 19 design smells
    • Detects 11 implementation smells
    • Computes various object-oriented code metrics
    • Provides smell trend analysis of Git repositories
    • Many visualization aids including smell treemap,
    and smell sunburst
    • Detects code duplication
    • Allows customization of analysis
    • Smart tracking of detected smells
    http://www.designite-tools.com
    Academic license is free!

    View Slide

  27. God Component
    when a component is excessively large
    either in the terms of
    LOC or number of classes.

    View Slide

  28. Cyclic Dependency
    When two or more architecture
    components depend on each
    other directly or indirectly

    View Slide

  29. Stable Dependencies Principle (SDP)
    dependencies between packages should be in the direction of the
    stability of the packages.
    =

    (
    +
    )
    Ca - afferent coupling (or incoming dependencies)
    Ce - efferent coupling (or outgoing dependencies)

    View Slide

  30. Unstable Dependencies
    when a component depends on
    other components that are less
    stable than itself.
    IA
    < IB
    A
    B

    View Slide

  31. Feature Concentration
    A1, A2
    D1 C1, C2, C3, C4
    when a component is realizing more
    than one architectural
    concern/feature.
    In other words, the component is not
    cohesive.
    B1

    View Slide

  32. Ambiguous interface
    when a component offers only a
    single, general entry-point into the
    component.

    View Slide

  33. Scattered functionality
    when multiple components are
    responsible for realizing the same
    high-level concern

    View Slide

  34. Dense Structure
    Average degree = 2 ∗||
    ||
    when components have excessive
    and dense dependencies without
    any particular structure.

    View Slide

  35. Architecture smells in open-source projects
    Arch smells #Instances Smell density
    Cyclic dependency 34,556 0.415
    Feature concentration 17,420 0.209
    Scattered functionality 11,623 0.139
    Unstable dependency 10,195 0.122
    God component 4,774 0.057
    Ambiguous interface 852 0.010
    Dense structure 302 0.003
    Repositories: 3,209
    containing > 83
    MLOC (C#)

    View Slide

  36. Managing smells in practice

    View Slide

  37. Managing smells
    Prevent
    Detect and remove
    Awareness
    Processes
    Strategies

    View Slide

  38. Awareness
    Does the development team well aware about:
    • Smells and resultant technical debt
    • Their impact on their project
    • Code quality, clean code practices
    Train
    • Training
    • Books
    • Workshops/conferences
    • …

    View Slide

  39. Processes
    Employ pragmatic processes to bring discipline
    Review process
    • Code reviews
    Architecture governance
    • Adherence to collection of guidelines and controls
    People care about things that you measure and reward!

    View Slide

  40. Detecting and refactoring smells:
    Key strategies

    View Slide

  41. Detecting and refactoring smells: strategies
    1. Identify and track
    2. Prioritize
    3. Refactoring installments
    4. Follow the ‘Boy’s scout rule’
    5. Motivate
    6. Periodically, aim for large-scale
    refactoring
    7. Refactor, except

    View Slide

  42. Let us conclude

    View Slide

  43. A Hack

    View Slide

  44. J
    U
    G
    A
    A
    D
    Quality issues
    at architecture
    granularity

    View Slide

  45. An
    architecture
    smell
    A R C H I T E C T U R E S M E L L S
    J
    U
    G
    A
    A
    D

    View Slide

  46. Tool to detect
    smells
    A R C H I T E C T U R E S M E L L S
    O D C O M P O N E N T
    J
    U
    G
    A
    A
    D

    View Slide

  47. A way to
    improve
    A R C H I T E C T U R E S M E L L S
    O D C O M P O N E N T
    J
    U
    G
    A
    A
    D
    D
    E
    S
    I
    G
    N
    I
    T
    E

    View Slide

  48. A W A R E E S S
    G O D C O M P O N E N T
    D
    S
    I
    G
    N
    I
    T
    E
    J
    U
    G
    A
    A
    D
    A R C H I T E C T U R E S M E L L S

    View Slide

  49. Tushar Sharma
    [email protected]
    http://www.tusharma.in
    Thank you!!
    Courtesy: spikedmath.com

    View Slide