Does your design smell - Tushar Sharma
Transcript of Does your design smell - Tushar Sharma
![Page 1: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/1.jpg)
Does Your Design Smell?
Tushar Sharma
http://www.tusharma.in
![Page 2: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/2.jpg)
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](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/3.jpg)
![Page 4: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/4.jpg)
![Page 5: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/5.jpg)
![Page 6: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/6.jpg)
Missing road
![Page 7: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/7.jpg)
Unrestricted access
![Page 8: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/8.jpg)
Hub-like road
![Page 9: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/9.jpg)
Footpath is not a road
![Page 10: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/10.jpg)
Deadlock!!
![Page 11: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/11.jpg)
Multitasking
![Page 12: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/12.jpg)
Useless… unnecessary
![Page 13: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/13.jpg)
Complex
![Page 14: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/14.jpg)
Beyond capacity
![Page 15: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/15.jpg)
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](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/16.jpg)
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](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/17.jpg)
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](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/18.jpg)
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](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/19.jpg)
public class Throwable {public void printStackTrace(); //other methods elided.
}
(Java 1)
Throwable class in JDK
![Page 20: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/20.jpg)
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](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/21.jpg)
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](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/22.jpg)
In JDK7• 508 classes - at least one
public field• 96 classes - at least five
public fields
![Page 23: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/23.jpg)
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](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/24.jpg)
Component class in JDK
![Page 25: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/25.jpg)
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](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/26.jpg)
Stack is not a Vector
![Page 27: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/27.jpg)
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](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/28.jpg)
![Page 29: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/29.jpg)
This smell arises when an abstraction has more thanone responsibility assigned to it.
Multifaceted Abstraction
Multitasking
![Page 30: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/30.jpg)
Image class• load• process• render• store
Example
multiplereasons tochange
granularity of a responsibility
![Page 31: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/31.jpg)
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](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/32.jpg)
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](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/33.jpg)
InsufficientModularization
Beyond capacity!!Complex!!
![Page 34: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/34.jpg)
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](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/35.jpg)
![Page 36: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/36.jpg)
Tools to detect design smells
Infusion
![Page 37: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/37.jpg)
Tools to detect design smellsDesignite
http://www.designite-tools.com
![Page 38: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/38.jpg)
Tools to detect design smells
Designite
http://www.designite-tools.com
![Page 39: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/39.jpg)
Tools to detect design smells
Designite
http://www.designite-tools.com
![Page 40: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/40.jpg)
Tools to detect design smells
Designite
http://www.designite-tools.com
![Page 41: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/41.jpg)
Tools to detect design smells
Designite
http://www.designite-tools.com
![Page 42: Does your design smell - Tushar Sharma](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/42.jpg)
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](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/43.jpg)
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](https://reader038.fdocuments.in/reader038/viewer/2022103010/5886728e1a28ab7d408b6cf5/html5/thumbnails/44.jpg)
Tushar Sharma@[email protected]://www.tusharma.in