does your design smell - tushar sharma

44
Does Your Design Smell? Tushar Sharma http :// www . tusharma . in

Upload: avisi-bv

Post on 24-Jan-2017

39 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Does your design smell  - Tushar Sharma

Does Your Design Smell?

Tushar Sharma

http://www.tusharma.in

Page 2: Does your design smell  - Tushar Sharma

Cities grow, cities evolve, (...), each cityhas to be renewed in order to meet theneeds of its populace. From time to timecities are intentionally refactored (...);most times cities are refactored in bits(...), but sometimes the literal andfigurative debt is so great a once greatcity falls into despair (...).

Grady Booch

Page 3: Does your design smell  - Tushar Sharma
Page 4: Does your design smell  - Tushar Sharma
Page 5: Does your design smell  - Tushar Sharma
Page 6: Does your design smell  - Tushar Sharma

Missing road

Page 7: Does your design smell  - Tushar Sharma

Unrestricted access

Page 8: Does your design smell  - Tushar Sharma

Hub-like road

Page 9: Does your design smell  - Tushar Sharma

Footpath is not a road

Page 10: Does your design smell  - Tushar Sharma

Deadlock!!

Page 11: Does your design smell  - Tushar Sharma

Multitasking

Page 12: Does your design smell  - Tushar Sharma

Useless… unnecessary

Page 13: Does your design smell  - Tushar Sharma

Complex

Page 14: Does your design smell  - Tushar Sharma

Beyond capacity

Page 15: Does your design smell  - Tushar Sharma

Why?

Every engineering discipline has to deal withnon-optimal and sub-optimal solutions.

Such solutions violate fundamentalprinciples of the discipline.

Smells

Page 16: Does your design smell  - Tushar Sharma

Design smells

Design smells are certain structures in the design thatindicate violation of fundamental design principles and

negatively impact design quality.

Page 17: Does your design smell  - Tushar Sharma

Design smells

Design smells are certain structures in the design thatindicate violation of fundamental design principles and

negatively impact design quality.

Page 18: Does your design smell  - Tushar Sharma

Missing road

This smell arises when clumps ofdata or encoded strings are usedinstead of creating a class or an

interface.

Missing abstraction

Page 19: Does your design smell  - Tushar Sharma

public class Throwable {public void printStackTrace(); //other methods elided.

}

(Java 1)

Throwable class in JDK

Page 20: Does your design smell  - Tushar Sharma

public class Throwable {public void printStackTrace();public StackTraceElement[] getStackTrace();//other methods elided.

}

public final class StackTraceElement {public String getFileName();public int getLineNumber();public String getClassName();public String getMethodName();public boolean isNativeMethod();

}

Refactored in Java 1.4

(Java 1.4)

Page 21: Does your design smell  - Tushar Sharma

Unrestricted access

This smell occurs when the declared accessibilityof one or more members of an abstraction ismore permissive than actually required.

Deficient Encapsulation

Page 22: Does your design smell  - Tushar Sharma

In JDK7• 508 classes - at least one

public field• 96 classes - at least five

public fields

Page 23: Does your design smell  - Tushar Sharma

Hub-like road

This smell arises when an abstraction has dependencies(both incoming and outgoing) with a large number ofother abstractions.

Hub-likeModularization

Page 24: Does your design smell  - Tushar Sharma

Component class in JDK

Page 25: Does your design smell  - Tushar Sharma

Footpath is not a road

This smell arises when a supertype and its subtypeconceptually do not share an “IS-A” relationshipresulting in broken substitutability.

Broken Hierarchy

Page 26: Does your design smell  - Tushar Sharma

Stack is not a Vector

Page 27: Does your design smell  - Tushar Sharma

This smell arises when two or more abstractionsdepend on each other directly or indirectly.

Cyclically-dependentModularization

Deadlock!! Cycle!!

Page 28: Does your design smell  - Tushar Sharma
Page 29: Does your design smell  - Tushar Sharma

This smell arises when an abstraction has more thanone responsibility assigned to it.

Multifaceted Abstraction

Multitasking

Page 30: Does your design smell  - Tushar Sharma

Image class• load• process• render• store

Example

multiplereasons tochange

granularity of a responsibility

Page 31: Does your design smell  - Tushar Sharma

This smell occurs when an abstraction that is actuallynot needed (and thus could have been avoided) getsintroduced in a software design.

Unnecessary Abstraction

Useless… unnecessary

Page 32: Does your design smell  - Tushar Sharma

public interface WindowConstants {/**The do-nothing default window close operation*/public static final int DO_NOTHING_ON_CLOSE = 0;/**The hide-window default window close operation*/public static final int HIDE_ON_CLOSE = 1;/**The dispose-window default window close operation*/public static final int DISPOSE_ON_CLOSE = 2;/**The exit application default window close operation.*/public static final int EXIT_ON_CLOSE = 3;

}

Example

In javax.swing.WindowConstants

Page 33: Does your design smell  - Tushar Sharma

InsufficientModularization

Beyond capacity!!Complex!!

Page 34: Does your design smell  - Tushar Sharma

This smell arises when an abstraction exists that has notbeen completely decomposed, and a furtherdecomposition could reduce its size, implementationcomplexity, or both.

InsufficientModularization

Examples• SocketPermission

getMask method – CC=81• Component

259 public methods

Page 35: Does your design smell  - Tushar Sharma
Page 36: Does your design smell  - Tushar Sharma

Tools to detect design smells

Infusion

Page 37: Does your design smell  - Tushar Sharma

Tools to detect design smellsDesignite

http://www.designite-tools.com

Page 38: Does your design smell  - Tushar Sharma

Tools to detect design smells

Designite

http://www.designite-tools.com

Page 39: Does your design smell  - Tushar Sharma

Tools to detect design smells

Designite

http://www.designite-tools.com

Page 40: Does your design smell  - Tushar Sharma

Tools to detect design smells

Designite

http://www.designite-tools.com

Page 41: Does your design smell  - Tushar Sharma

Tools to detect design smells

Designite

http://www.designite-tools.com

Page 42: Does your design smell  - Tushar Sharma

Themessage

Every engineering discipline has to deal withnon-optimal and sub-optimal solutions.

Software engineering is not an exception;in fact, it is more prone to such smells.

Design smells – know them, avoidthem, and refactor them!

Page 43: Does your design smell  - Tushar Sharma

References

“Refactoring for software designsmells: Managing technical debt”By Girish Suryanarayana, Ganesh SG,and Tushar Sharma.Morgan Kaufmann. ISBN 978-0128013977

http://www.designsmells.com

Page 44: Does your design smell  - Tushar Sharma

Tushar Sharma@[email protected]://www.tusharma.in