2. Cities grow, cities evolve, (...), each city
has to be renewed in order to meet the
needs of its populace. From time to time
cities are intentionally refactored (...);
most times cities are refactored in bits
(...), but sometimes the literal and
figurative debt is so great a once great
city falls into despair (...).
Grady Booch
15. Why?
Every engineering discipline has to deal with
non-optimal and sub-optimal solutions.
Such solutions violate fundamental
principles of the discipline.
Smells
16. Design smells
Design smells are certain structures in the design that
indicate violation of fundamental design principles and
negatively impact design quality.
17. Design smells
Design smells are certain structures in the design that
indicate violation of fundamental design principles and
negatively impact design quality.
18. Missing road
This smell arises when clumps of
data or encoded strings are used
instead of creating a class or an
interface.
Missing abstraction
19. public class Throwable {
public void printStackTrace();
//other methods elided.
}
(Java 1)
Throwable class in JDK
20. 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)
21. Unrestricted access
This smell occurs when the declared accessibility
of one or more members of an abstraction is
more permissive than actually required.
Deficient Encapsulation
22. In JDK7
• 508 classes - at least one
public field
• 96 classes - at least five
public fields
23. Hub-like road
This smell arises when an abstraction has dependencies
(both incoming and outgoing) with a large number of
other abstractions.
Hub-like Modularization
25. Footpath is not a road
This smell arises when a supertype and its subtype
conceptually do not share an “IS-A” relationship
resulting in broken substitutability.
Broken Hierarchy
27. This smell arises when two or more abstractions
depend on each other directly or indirectly.
Cyclically-dependent
Modularization
Deadlock!! Cycle!!
28.
29. This smell arises when an abstraction has more than
one responsibility assigned to it.
Multifaceted Abstraction
Multitasking
30. Image class
• load
• process
• render
• store
Example
multiple
reasons to
change
granularity of a responsibility
31. This smell occurs when an abstraction that is actually
not needed (and thus could have been avoided) gets
introduced in a software design.
Unnecessary Abstraction
Useless… unnecessary
32. 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
34. This smell arises when an abstraction exists that has not
been completely decomposed, and a further
decomposition could reduce its size, implementation
complexity, or both.
Insufficient Modularization
Examples
• SocketPermission
getMask method – CC=81
• Component
259 public methods
37. Tools to detect design smells
Designite
http://www.designite-tools.com
38. Tools to detect design smells
Designite
http://www.designite-tools.com
39. Tools to detect design smells
Designite
http://www.designite-tools.com
40. Tools to detect design smells
Designite
http://www.designite-tools.com
41. Tools to detect design smells
Designite
http://www.designite-tools.com
42. The message
Every engineering discipline has to deal with
non-optimal and sub-optimal solutions.
Software engineering is not an exception;
in fact, it is more prone to such smells.
Design smells – know them, avoid
them, and refactor them!
43. References
“Refactoring for software design
smells: Managing technical debt”
By Girish Suryanarayana, Ganesh SG,
and Tushar Sharma.
Morgan Kaufmann. ISBN 978-0128013977
http://www.designsmells.com