SlideShare a Scribd company logo
How to Apply Design
Principles in Practice?
Ganesh Samarthyam
Entrepreneur; Author; Conf. speaker
ganesh@codeops.tech
www.designsmells.com; www.codeops.tech
"The critical design tool for software development
is a mind well educated in design principles.
It is not the UML or any other technology"
- Craig Larman
Why care about design quality and
design principles?
"We thought we were just programming on an airplane”
- Kent Beck
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,&not&on&concre8ons&
Dependency'Inversion'
Principle'(DIP)'
•  Many&clientGspecific&interfaces&are&beHer&than&one&
generalGpurpose&interface&
Interface'Segrega<on'
Principle'(ISP)'
Booch’s fundamental principles
Principles*
Abstrac/on*
Encapsula/on*
Modulariza/on*
Hierarchy*
How to apply principles in practice?
Principles
Code
How to bridge
the gap?
Proactive application: enabling techniques
Discussion example
Violates Single
Responsibility
Principle (SRP)
Completeness: Example
Discussion Example
Principle of Least Astonishment: Example
Discussion Example
Use “enabling techniques” to apply
design principles in practice
Key-takeaway
#1
Design smells: example
Discussion example
// using java.util.Date
Date today = new Date();
System.out.println(today);
$ java DateUse
Wed Dec 02 17:17:08 IST 2015
Why should we get the
time and timezone details
if I only want a date? Can
I get rid of these parts?
No!
“So what”!
Date today = new Date();
System.out.println(today);
Date todayAgain = new Date();
System.out.println(todayAgain);
System.out.println(today.compareTo(todayAgain) == 0);
Thu Mar 17 13:21:55 IST 2016
Thu Mar 17 13:21:55 IST 2016
false
What is going
on here?
Refactoring for Date
Replace inheritance
with delegation
java.time package!
Refactored solution
LocalDate today = LocalDate.now();
System.out.println(today);
LocalDate todayAgain = LocalDate.now();
System.out.println(todayAgain);
System.out.println(today.compareTo(todayAgain) == 0);
2016-03-17
2016-03-17
true
Works fine
now!
Refactored example …
You can use only date,
time, or even timezone,
and combine them as
needed!
LocalDate today = LocalDate.now();
System.out.println(today);
LocalTime now = LocalTime.now();
System.out.println(now);
ZoneId id = ZoneId.of("Asia/Tokyo");
System.out.println(id);
LocalDateTime todayAndNow = LocalDateTime.now();
System.out.println(todayAndNow);
ZonedDateTime todayAndNowInTokyo = ZonedDateTime.now(ZoneId.of("Asia/Tokyo"));
System.out.println(todayAndNowInTokyo);
2016-03-17
13:28:06.927
Asia/Tokyo
2016-03-17T13:28:06.928
2016-03-17T16:58:06.929+09:00[Asia/Tokyo]
More classes in Date/Time API
What’s that smell?
switch'(transferType)'{'
case'DataBuffer.TYPE_BYTE:'
byte'bdata[]'='(byte[])inData;'
pixel'='bdata[0]'&'0xff;'
length'='bdata.length;'
break;'
case'DataBuffer.TYPE_USHORT:'
short'sdata[]'='(short[])inData;'
pixel'='sdata[0]'&'0xffff;'
length'='sdata.length;'
break;'
case'DataBuffer.TYPE_INT:'
int'idata[]'='(int[])inData;'
pixel'='idata[0];'
length'='idata.length;'
break;'
default:'
throw' new' UnsupportedOperaQonExcepQon("This' method' has' not' been' "+' "implemented'
for'transferType'"'+'transferType);'
}'
Don’t repeat yourself (DRY) principle
protected(int(transferType;! protected(DataBuffer(dataBuffer;!
pixel(=(dataBuffer.getPixel();(
length(=(dataBuffer.getSize();!
switch((transferType)({(
case(DataBuffer.TYPE_BYTE:(
byte(bdata[](=((byte[])inData;(
pixel(=(bdata[0](&(0xff;(
length(=(bdata.length;(
break;(
case(DataBuffer.TYPE_USHORT:(
short(sdata[](=((short[])inData;(
pixel(=(sdata[0](&(0xffff;(
length(=(sdata.length;(
break;(
case(DataBuffer.TYPE_INT:(
int(idata[](=((int[])inData;(
pixel(=(idata[0];(
length(=(idata.length;(
break;(
default:(
throw( new( UnsupportedOperaRonExcepRon("This( method(
has( not( been( "+( "implemented( for( transferType( "( +(
transferType);(
}!
Refactor “bad smells” to apply
design principles in practice
Key-takeaway
#2
Tool driven approach for design
quality
Comprehension tools
STAN
http://stan4j.com
Comprehension tools
Code City
http://www.inf.usi.ch/phd/wettel/codecity.html
Comprehension tools
Imagix 4D
http://www.imagix.com
Critique, code-clone detectors, and metric tools
Infusion
www.intooitus.com/products/infusion
Critique, code-clone detectors, and metric tools
Designite
www.designite-tools.com
Critique, code-clone detectors, and metric tools
PMD Copy Paste Detector (CPD)
http://pmd.sourceforge.net/pmd-4.3.0/cpd.html
Critique, code-clone detectors, and metric tools
Understand
https://scitools.com
Technical debt quantification/visualization tools
Sonarqube
http://www.sonarqube.org
Refactoring tools
ReSharper
https://www.jetbrains.com/resharper/features/
Use design analysis tools to apply
design principles in practice
Key-takeaway
#3
Key take-aways
❖ Thee effective ways to apply design principles in
practice:
❖ Use “enabling techniques”
❖ Refactoring “bad smells”
❖ Use design analysis tools
Proactive application: enabling techniques
Reactive application: refactoring smells
Enablers: tools for refactoring
Jhawk&
(Java)&
CodeCity&&
(C++,&Java,&C#)&&
CppDepend&
(C++)&
Sotograph&
(C++,&Java,&C#)&
Imagix&4D&&
(C,&C++,&Java)&
La?x&
(C/C++,&Java,&C#)&&
SolidSX&&
(C++,&Java,&C#)&
Bauhaus&
(C/C++,&Java,&C#)&
Structure101&&
(Java,&C#)&
Understand&&
(C/C++,&Java,&C#)&
Simian&
(C/C++,&Java,&C#,&…)&
Jarchitect&
(Java)&
Ndepend&
(C#)&
Stan4J&
(Java)&
InFusion&
(C/C++,&Java)&
InCode&
(C/C++,&Java)&
Our upcoming workshops
Modern Software Architecture - July 2
Modern Programming with Java 8 - July 16
Software Refactoring in Practice - July 23
www.codeops.tech
www.designsmells.com
ocpjava.wordpress.com
ganesh@codeops.tech
bit.ly/sgganesh
@GSamarthyam

More Related Content

Similar to How to Apply Design Principles in Practice (20)

PDF
Refactoring for Software Design Smells - Tech Talk
Ganesh Samarthyam
 
PDF
Software Architecture: Principles, Patterns and Practices
Ganesh Samarthyam
 
PPTX
Java 8
Raghda Salah
 
PDF
Refactoring for Software Design Smells
Ganesh Samarthyam
 
PPTX
...and thus your forms automagically disappeared
Luc Bors
 
PDF
Architecture refactoring - accelerating business success
Ganesh Samarthyam
 
PDF
Comunicare, condividere e mantenere decisioni architetturali nei team di svil...
Michele Orselli
 
PDF
Java 8 Date and Time API
Ganesh Samarthyam
 
PPTX
Code Refactoring
Milan Vukoje
 
PDF
Building a Sustainable Data Platform on AWS
SmartNews, Inc.
 
PDF
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Fwdays
 
PPTX
Data Science Challenge presentation given to the CinBITools Meetup Group
Doug Needham
 
PPTX
Cloudera Data Science Challenge
Mark Nichols, P.E.
 
ODP
Intro To Spring Python
gturnquist
 
PDF
Down With JavaScript!
Garth Gilmour
 
PPTX
Apex code Benchmarking
Amit Chaudhary
 
PPTX
ProgrammingPrimerAndOOPS
sunmitraeducation
 
PPTX
AngularConf2015
Alessandro Giorgetti
 
PPTX
The advantage of developing with TypeScript
Corley S.r.l.
 
PDF
Beyond Breakpoints: A Tour of Dynamic Analysis
C4Media
 
Refactoring for Software Design Smells - Tech Talk
Ganesh Samarthyam
 
Software Architecture: Principles, Patterns and Practices
Ganesh Samarthyam
 
Java 8
Raghda Salah
 
Refactoring for Software Design Smells
Ganesh Samarthyam
 
...and thus your forms automagically disappeared
Luc Bors
 
Architecture refactoring - accelerating business success
Ganesh Samarthyam
 
Comunicare, condividere e mantenere decisioni architetturali nei team di svil...
Michele Orselli
 
Java 8 Date and Time API
Ganesh Samarthyam
 
Code Refactoring
Milan Vukoje
 
Building a Sustainable Data Platform on AWS
SmartNews, Inc.
 
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Fwdays
 
Data Science Challenge presentation given to the CinBITools Meetup Group
Doug Needham
 
Cloudera Data Science Challenge
Mark Nichols, P.E.
 
Intro To Spring Python
gturnquist
 
Down With JavaScript!
Garth Gilmour
 
Apex code Benchmarking
Amit Chaudhary
 
ProgrammingPrimerAndOOPS
sunmitraeducation
 
AngularConf2015
Alessandro Giorgetti
 
The advantage of developing with TypeScript
Corley S.r.l.
 
Beyond Breakpoints: A Tour of Dynamic Analysis
C4Media
 

More from Ganesh Samarthyam (20)

PDF
Wonders of the Sea
Ganesh Samarthyam
 
PDF
Animals - for kids
Ganesh Samarthyam
 
PDF
Applying Refactoring Tools in Practice
Ganesh Samarthyam
 
PDF
CFP - 1st Workshop on “AI Meets Blockchain”
Ganesh Samarthyam
 
PDF
Great Coding Skills Aren't Enough
Ganesh Samarthyam
 
PDF
College Project - Java Disassembler - Description
Ganesh Samarthyam
 
PDF
Coding Guidelines - Crafting Clean Code
Ganesh Samarthyam
 
PDF
Design Patterns - Compiler Case Study - Hands-on Examples
Ganesh Samarthyam
 
PDF
Bangalore Container Conference 2017 - Brief Presentation
Ganesh Samarthyam
 
PDF
Bangalore Container Conference 2017 - Poster
Ganesh Samarthyam
 
PDF
OO Design and Design Patterns in C++
Ganesh Samarthyam
 
PDF
Bangalore Container Conference 2017 - Sponsorship Deck
Ganesh Samarthyam
 
PDF
Let's Go: Introduction to Google's Go Programming Language
Ganesh Samarthyam
 
PPT
Google's Go Programming Language - Introduction
Ganesh Samarthyam
 
PDF
Java Generics - Quiz Questions
Ganesh Samarthyam
 
PDF
Java Generics - by Example
Ganesh Samarthyam
 
PDF
Software Architecture - Quiz Questions
Ganesh Samarthyam
 
PDF
Docker by Example - Quiz
Ganesh Samarthyam
 
PDF
Core Java: Best practices and bytecodes quiz
Ganesh Samarthyam
 
PDF
Advanced Debugging Using Java Bytecodes
Ganesh Samarthyam
 
Wonders of the Sea
Ganesh Samarthyam
 
Animals - for kids
Ganesh Samarthyam
 
Applying Refactoring Tools in Practice
Ganesh Samarthyam
 
CFP - 1st Workshop on “AI Meets Blockchain”
Ganesh Samarthyam
 
Great Coding Skills Aren't Enough
Ganesh Samarthyam
 
College Project - Java Disassembler - Description
Ganesh Samarthyam
 
Coding Guidelines - Crafting Clean Code
Ganesh Samarthyam
 
Design Patterns - Compiler Case Study - Hands-on Examples
Ganesh Samarthyam
 
Bangalore Container Conference 2017 - Brief Presentation
Ganesh Samarthyam
 
Bangalore Container Conference 2017 - Poster
Ganesh Samarthyam
 
OO Design and Design Patterns in C++
Ganesh Samarthyam
 
Bangalore Container Conference 2017 - Sponsorship Deck
Ganesh Samarthyam
 
Let's Go: Introduction to Google's Go Programming Language
Ganesh Samarthyam
 
Google's Go Programming Language - Introduction
Ganesh Samarthyam
 
Java Generics - Quiz Questions
Ganesh Samarthyam
 
Java Generics - by Example
Ganesh Samarthyam
 
Software Architecture - Quiz Questions
Ganesh Samarthyam
 
Docker by Example - Quiz
Ganesh Samarthyam
 
Core Java: Best practices and bytecodes quiz
Ganesh Samarthyam
 
Advanced Debugging Using Java Bytecodes
Ganesh Samarthyam
 
Ad

Recently uploaded (20)

PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
Ad

How to Apply Design Principles in Practice