applying design principles in practice
TRANSCRIPT
![Page 1: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/1.jpg)
Applying Design Principles in Practice
Tushar Sharma Ganesh SamarthyamGirish Suryanarayana
![Page 2: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/2.jpg)
Agenda• Introduction
• Applying abstraction
• Applying encapsulation
• Applying modularisation
• Applying hierarchy
• Practical considerations
• Wrap-up
![Page 3: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/3.jpg)
Why care about design quality and design principles?
![Page 4: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/4.jpg)
Poor software quality costs more than $150 billion per year
in U.S. and greater than $500 billion per year worldwide
- Capers Jones
![Page 5: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/5.jpg)
The city metaphor
Source: http://indiatransportportal.com/wp-content/uploads/2012/04/Traffic-congestion1.jpg
![Page 6: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/6.jpg)
“Applying design principles is the key to creating high-quality software!”
Architectural principles: Axis, symmetry, rhythm, datum, hierarchy, transformation
![Page 7: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/7.jpg)
What do we mean by “principles”?
“Design principles are key notions considered fundamental to many different software design
approaches and concepts.” - SWEBOK ‘04
![Page 8: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/8.jpg)
"The critical design tool for software development is a mind well educated in design principles"
- Craig Larman
![Page 9: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/9.jpg)
Fundamental Design Principles
![Page 10: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/10.jpg)
SOLID principles• There&should&never&be&more&than&one&reason&for&a&class&to&change&&
Single'Responsibility'Principle'(SRP)'
• So6ware&en88es&(classes,&modules,&func8ons,&etc.)&should&be&open&for&extension,&but&closed&for&modifica8on&
Open'Closed'Principle'(OCP)'
• Pointers&or&references&to&base&classes&must&be&able&to&use&objects&of&derived&classes&without&knowing&it&
Liskov’s'Subs<tu<on'Principle'(LSP)'
• Depend&on&abstrac8ons,¬&on&concre8ons&Dependency'Inversion'Principle'(DIP)'
• Many&clientGspecific&interfaces&are&beHer&than&one&generalGpurpose&interface&
Interface'Segrega<on'Principle'(ISP)'
![Page 11: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/11.jpg)
3 principles behind patterns
Program to an interface, not to an implementation
Favor object composition over inheritance
Encapsulate what varies
![Page 12: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/12.jpg)
Booch’s fundamental principles
Principles*
Abstrac/on*
Encapsula/on*
Modulariza/on*
Hierarchy*
![Page 13: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/13.jpg)
How to apply principles in practice?Abstraction Encapsulation Modularization Hierarchy
Code
How to bridge the gap?
![Page 14: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/14.jpg)
Real scenario #1Initial design
![Page 15: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/15.jpg)
Real scenario #1
❖ How will you refactor such that:
❖ A specific DES, AES, TDES, … can be “plugged” at runtime?
❖ Reuse these algorithms in new contexts?
❖ Easily add support for new algorithms in Encryption?
Next change: smelly design
![Page 16: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/16.jpg)
Time to refactor!Three strikes and you
refactor
Martin Fowler
![Page 17: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/17.jpg)
Potential solution #1?Broken
hierarchy!
![Page 18: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/18.jpg)
Potential solution #2?Algorithms not
reusable!
![Page 19: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/19.jpg)
Potential solution #3?
![Page 20: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/20.jpg)
Can you identify the pattern?
![Page 21: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/21.jpg)
You’re right: Its Strategy pattern!
![Page 22: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/22.jpg)
Real scenario #2
Initial design
![Page 23: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/23.jpg)
Real scenario #2How to add support for new
content types and/or algorithms?
![Page 24: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/24.jpg)
How about this solution?
![Page 25: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/25.jpg)
Can you identify the pattern structure?
![Page 26: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/26.jpg)
You’re right: Its Bridge pattern structure!
![Page 27: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/27.jpg)
Wait, what principle did we apply?
![Page 28: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/28.jpg)
Open Closed Principle (OCP)
Bertrand Meyer
Software entities should be open for extension, but closed for modification
![Page 29: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/29.jpg)
Variation Encapsulation Principle (VEP)
Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides
Encapsulate the concept that varies
![Page 30: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/30.jpg)
Fundamental principle: Encapsulation
The principle of encapsulation advocates separation of concerns andinformation hiding through techniques such as hiding implementation
details of abstractions and hiding variations
![Page 31: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/31.jpg)
Enabling techniques for encapsulation
![Page 32: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/32.jpg)
Design principles and enabling techniques
![Page 33: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/33.jpg)
What is refactoring?Refactoring (noun): a change
made to the internal structure of software to make it easier to understand and cheaper to modify without changing its
observable behavior
Refactor (verb): to restructure software by applying a series
of refactorings without changing its observable
behavior
![Page 34: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/34.jpg)
Applying principles in practice
EncapsulationViolating
encapsulationAdherence to encapsulation
Enabling technique:
Hide variations
![Page 35: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/35.jpg)
Applying principles in practice
PrincipleViolatingprinciples
Adherence to principles
Refactoring
Bad design (with smells)
Good design (with patterns)
![Page 36: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/36.jpg)
Design determines qualities
Understandability Changeability Extensibility
Reusability Testability Reliability
DESIGNimpacts
impactsimpacts
![Page 37: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/37.jpg)
Smells approach to learn principles
A"good"designer"is"one"who"knows"the"design"solu1ons"
A"GREAT"designer"is"one"who"understands"the"impact"of"design"smells"and"knows"
how"to"address"them!
![Page 38: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/38.jpg)
Agenda• Introduction
• Applying abstraction
• Applying encapsulation
• Applying modularisation
• Applying hierarchy
• Practical considerations
• Wrap-up
![Page 39: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/39.jpg)
What is abstraction?
![Page 40: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/40.jpg)
public'class'Throwable'{'//'following'method'is'available'from'Java'1.0'version.''
//'Prints'the'stack'trace'as'a'string'to'standard'output''
//'for'processing'a'stack'trace,''
//'we'need'to'write'regular'expressions''
public'void'printStackTrace();''''''
//'other'methods'elided''
}'
![Page 41: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/41.jpg)
Refactoring for this smellpublic'class'Throwable'{'
//'following'method'is'available'from'Java'1.0'version.''
//'Prints'the'stack'trace'as'a'string'to'standard'output''
//'for'processing'a'stack'trace,''
//'we'need'to'write'regular'expressions''
public'void'printStackTrace();''''''
//'other'methods'elided''
}'
public'class'Throwable'{'
public'void'printStackTrace();''''''
''''''''''''public'StackTraceElement[]'getStackTrace();'//'Since'1.4'
'''''''''''''//'other'methods'elided''
}'
public'final'class'StackTraceElement'{'
public'String'getFileName();'
public'int'getLineNumber();'
public'String'getClassName();'
public'String'getMethodName();'
public'boolean'isNativeMethod();'
}'
![Page 42: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/42.jpg)
Applying abstraction principle
Provide a crisp conceptual boundary and a unique identity
![Page 43: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/43.jpg)
public class FormattableFlags { // Explicit instantiation of this class is prohibited. private FormattableFlags() {} /** Left-justifies the output. */ public static final int LEFT_JUSTIFY = 1<<0; // '-' /** Converts the output to upper case */ public static final int UPPERCASE = 1<<1; // 'S' /**Requires the output to use an alternate form. */ public static final int ALTERNATE = 1<<2; // '#'
}
![Page 44: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/44.jpg)
class Currency { public static String DOLLAR = "\u0024"; public static String EURO = "\u20AC"; public static String RUPEE = "\u20B9"; public static String YEN = "\u00A5"; // no other members in this class
}
![Page 45: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/45.jpg)
Applying abstraction principle
Assign single and meaningful responsibility
![Page 46: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/46.jpg)
Enabling techniques for abstraction
![Page 47: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/47.jpg)
Agenda• Introduction
• Applying abstraction
• Applying encapsulation
• Applying modularisation
• Applying hierarchy
• Practical considerations
• Wrap-up
![Page 48: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/48.jpg)
What is encapsulation?
![Page 49: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/49.jpg)
![Page 50: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/50.jpg)
![Page 51: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/51.jpg)
Refactoring for that smell
![Page 52: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/52.jpg)
Applying encapsulation principle
Hide implementation details
![Page 53: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/53.jpg)
ScenarioInitial design
TextView
+ Draw()
BorderedTextView
+ Draw()+ DrawBorder()
![Page 54: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/54.jpg)
Real scenario
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
![Page 55: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/55.jpg)
Supporting new requirementsRevised design with new requirements
TextView
+ Draw()
BorderedTextView
+ Draw()+ DrawBorder()
ScrollableTextView ScrollableBorderedTextView
- borderWidth
+ Draw()+ ScrollTo()
- ScrollPosition
+ Draw()+ ScrollTo()+ DrawBorder()
- ScrollPosition- borderWidth
![Page 56: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/56.jpg)
Real scenario
❖ How will you refactor such that:
❖ You don't have to “multiply-out” sub-types? (i.e., avoid “explosion of classes”)
❖ Add or remove responsibilities (e.g., scrolling) at runtime?
Next change: smelly design
![Page 57: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/57.jpg)
How about this solution?VisualComponent
+ Draw()
TextView
+ Draw()
ScrollDecortor BorderDecorator
+ Draw()+ ScrollTo()
- ScrollPosition
+ Draw()+ DrawBorder()
- borderWidth
Decorator
+ Draw() component->Draw()
Decorator::Draw()DrawBorder()Decorator::Draw()
ScrollTo()
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
![Page 58: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/58.jpg)
At runtime (object diagram)
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
![Page 59: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/59.jpg)
Can you identify the pattern?VisualComponent
+ Draw()
TextView
+ Draw()
ScrollDecortor BorderDecorator
+ Draw()+ ScrollTo()
- ScrollPosition
+ Draw()+ DrawBorder()
- borderWidth
Decorator
+ Draw() component->Draw()
Decorator::Draw()DrawBorder()Decorator::Draw()
ScrollTo()
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
![Page 60: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/60.jpg)
You’re right: Its Decorator pattern!
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
![Page 61: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/61.jpg)
Decorator pattern: Discussion
❖ Want to add responsibilities to individual objects (not an entire class)
❖ One way is to use inheritance
❖ Inflexible; static choice
❖ Hard to add and remove responsibilities dynamically
Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality
❖ Add responsibilities through decoration
❖ in a way transparent to the clients
❖ Decorator forwards the requests to the contained component to perform additional actions
❖ Can nest recursively
❖ Can add an unlimited number of responsibilities dynamically
![Page 62: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/62.jpg)
Identify pattern used in this code
LineNumberReader lnr = new LineNumberReader( new BufferedReader( new FileReader(“./test.c")));
String str = null;
while((str = lnr.readLine()) != null) System.out.println(lnr.getLineNumber() + ": " + str);
![Page 63: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/63.jpg)
Decorator pattern in Reader
![Page 64: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/64.jpg)
Scenarioa) How do we treat files
and folders alike?b) How can we handle
shortcuts?
File
+ GetName()+ GetSize()+ …
- name: String- size: int- type: FileType- data: char[]- …
Folder
+ GetName()+ GetFiles()+ GetFolders()+ …
- name: String - files[]: File- folders[]: Folder
![Page 65: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/65.jpg)
How about this solution?FileItem
+ GetName()+ GetSize()+ Add(FileItem)+ Remove(FileItem)
Folder
+ GetFiles()+ …
File
- files: FileItem
+ GetType()+ GetContents()+ …
- type: FileType- data: char[]
Shortcut
+ GetLinkedFileItem()+ …
- linkToFile: FileItem
![Page 66: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/66.jpg)
Composite pattern
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
![Page 67: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/67.jpg)
Composite pattern: Discussion
❖ There are many situations where a group of components form larger components
❖ Simplistic approach: Make container component contain primitive ones ❖ Problem: Code has to treat
container and primitive components differently
Compose objects into tree structures to represent part-whole hierarchies. Composite lets client treat individual objects and compositions of objects uniformly.
❖ Perform recursive composition of components
❖ Clients don’t have to treat container and primitive components differently
![Page 68: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/68.jpg)
Decorator vs. CompositeDecorator and composite structure looks similar:
Decorator is a degenerate form of Composite!
Decorator Composite
At max. one component Can have many components
Adds responsibilities Aggregates objects
Does not make sense to have methods such as Add(),
Remove(), GetChid() etc.
Has methods such as Add(), Remove(), GetChild(), etc.
![Page 69: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/69.jpg)
Applying encapsulation principle
Hide variations
![Page 70: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/70.jpg)
Enabling techniques for encapsulation
![Page 71: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/71.jpg)
Agenda• Introduction
• Applying abstraction
• Applying encapsulation
• Applying modularisation
• Applying hierarchy
• Practical considerations
• Wrap-up
![Page 72: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/72.jpg)
What is modularization?
![Page 73: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/73.jpg)
![Page 74: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/74.jpg)
Refactoring for this smell
![Page 75: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/75.jpg)
Applying modularisation principle
Localize related data and methods
![Page 76: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/76.jpg)
![Page 77: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/77.jpg)
Suggested refactoring for this smell
![Page 78: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/78.jpg)
Applying modularisation principle
Create acyclic dependencies
![Page 79: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/79.jpg)
Enabling techniques for modularisation
![Page 80: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/80.jpg)
Agenda• Introduction
• Applying abstraction
• Applying encapsulation
• Applying modularisation
• Applying hierarchy
• Practical considerations
• Wrap-up
![Page 81: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/81.jpg)
What is hierarchy?
![Page 82: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/82.jpg)
public Insets getBorderInsets(Component c, Insets insets){
Insets margin = null;
// Ideally we'd have an interface defined for classes which
// support margins (to avoid this hackery), but we've
// decided against it for simplicity
//
if (c instanceof AbstractButton) {
margin = ((AbstractButton)c).getMargin();
} else if (c instanceof JToolBar) {
margin = ((JToolBar)c).getMargin();
} else if (c instanceof JTextComponent) {
margin = ((JTextComponent)c).getMargin();
}
// rest of the code elided …
![Page 83: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/83.jpg)
Suggested refactoring for this smell
![Page 84: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/84.jpg)
Suggested refactoring for the code
margin = c.getMargin();
if (c instanceof AbstractButton) {
margin = ((AbstractButton)c).getMargin();
} else if (c instanceof JToolBar) {
margin = ((JToolBar)c).getMargin();
} else if (c instanceof JTextComponent) {
margin = ((JTextComponent)c).getMargin();
}
![Page 85: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/85.jpg)
Applying hierarchy principle
Apply meaningful classification
![Page 86: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/86.jpg)
![Page 87: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/87.jpg)
Suggested refactoring for this smell
![Page 88: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/88.jpg)
A real-world case study
![Page 89: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/89.jpg)
Applying hierarchy principle
Ensure proper ordering
![Page 90: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/90.jpg)
Enabling techniques for hierarchy
![Page 91: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/91.jpg)
Agenda• Introduction
• Applying abstraction
• Applying encapsulation
• Applying modularisation
• Applying hierarchy
• Practical considerations
• Wrap-up
![Page 92: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/92.jpg)
How to repay technical debt in practice?
![Page 93: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/93.jpg)
IMPACT process model
![Page 94: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/94.jpg)
Useful tools during Refactoring
![Page 96: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/96.jpg)
Comprehension Tools
Code Cityhttp://www.inf.usi.ch/phd/wettel/codecity.html
![Page 97: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/97.jpg)
Comprehension Tools
Imagix 4Dhttp://www.imagix.com
![Page 98: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/98.jpg)
Critique, code-clone detectors, and metric tools
Infusionwww.intooitus.com/products/infusion
![Page 99: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/99.jpg)
Critique, code-clone detectors, and metric tools
Designitewww.designite-tools.com
![Page 100: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/100.jpg)
Critique, code-clone detectors, and metric tools
PMD Copy Paste Detector (CPD)http://pmd.sourceforge.net/pmd-4.3.0/cpd.html
![Page 101: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/101.jpg)
Critique, code-clone detectors, and metric tools
Understandhttps://scitools.com
![Page 102: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/102.jpg)
Technical Debt quantification/visualization tools
Sonarqubehttp://www.sonarqube.org
![Page 103: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/103.jpg)
Refactoring tools
ReSharperhttps://www.jetbrains.com/resharper/features/
![Page 104: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/104.jpg)
Agenda• Introduction
• Applying abstraction
• Applying encapsulation
• Applying modularisation
• Applying hierarchy
• Practical considerations
• Wrap-up
![Page 105: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/105.jpg)
![Page 106: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/106.jpg)
Principles and enabling techniques
![Page 107: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/107.jpg)
“Applying design principles is the key to creating high-quality software!”
Architectural principles: Axis, symmetry, rhythm, datum, hierarchy, transformation
![Page 108: Applying Design Principles in Practice](https://reader035.vdocuments.net/reader035/viewer/2022081419/55a897f41a28ab143e8b46ef/html5/thumbnails/108.jpg)
[email protected]@GSamarthyam
[email protected]@Sharma__Tushar
[email protected]@Girish_Sur
www.designsmells.com @designsmells