SlideShare a Scribd company logo
Refactoring for
Software Design Smells
Ganesh Samarthyam
ganesh.samarthyam@gmail.com
“Applying design principles is the key to creating
high-quality software!”
Architectural principles:
Axis, symmetry, rhythm, datum, hierarchy, transformation
Who coined the
term “code
smell”?
Kent Beck
Who coined the
acronym “SOLID”?
(as in SOLID
principles)
Michael
Feathers
S
Single Responsibility
Principle
Every object should have a single responsibility and
that should be encapsulated by the class
O Open Closed Principle
Software should be open for extension, but closed for
modification
L
Liskov’s Substitution
Principle
Any subclass should always be usable instead of its
parent class
I
Interface Segregation
Principle
Many client specific interfaces are better than one
general purpose interface
D
Dependency Inversion
Principle
Abstractions should not depend upon details. Details
should depend upon abstractions
Why Care About Design Quality?
When,	due	to	constraints,	I	design	
quickly	and	dirty,	my	project	is	
loaded	with	technical	debt
Tool: Sonar!
Sonarqube
http://www.sonarqube.org
The City Metaphor
Source: http://indiatransportportal.com/wp-content/uploads/2012/04/Traffic-congestion1.jpg
The City Metaphor
“Cities grow, cities evolve, cities
have parts that simply die while other
parts flourish; each city has to be
renewed in order to meet the needs of its
populace… Software-intensive systems
are like that. They grow, they evolve,
sometimes they wither away, and
sometimes they flourish…”
Grady Booch in the foreword for “Refactoring for Software Design Smells: Managing Technical Debt”, Girish Suryanarayana, Ganesh Samarthyam, Tushar Sharma, Morgan Kaufmann/Elsevier, 2014.
Tool: CodeCity!
What are Smells?
“Smells'are'certain'structures'
in'the'code'that'suggest'
(some4mes'they'scream'for)'
the'possibility'of'refactoring.”''
Smell Example
logger.severe(“details”)
errlog.log(“details”)logger.error(“details”)
System.err.println(“details”)
Since ROI (Return On Investment)
is not clear, how to get
management buy-in for this
refactoring?
Log4j java.util.logging custom log library SOPs
Granularity of Smells
Architectural+
+
Cyclic&dependencies&between&modules&
Monolithic&modules&&
Layering&viola9ons&(back&layer&call,&skip&layer&call,&ver9cal&layering,&
etc)&
Design+
+
God&class&
Refused&bequest&&
Cyclic&dependencies&between&classes&
Code+(implementa6on)++
+
Internal&duplica9on&(clones&within&a&class)&&
Large&method&&
Temporary&field&&
Architecture Smell Example
Design Smell Example
Code Smell Example
class%GraphicsDevice%
%public%void%setFullScreenWindow(Window%w)%{%
%%%%%%%%if%(w%!=%null)%{%
%%%%%%%%%%%%if%(w.getShape()%!=%null)%{%w.setShape(null);%}%
%%%%%%%%%%%%if%(w.getOpacity()%<%1.0f)%{%w.setOpacity(1.0f);%}%
%%%%%%%%%%%%if%(!w.isOpaque())%{%
%%%%%%%%%%%%%%%%Color%bgColor%=%w.getBackground();%
%%%%%%%%%%%%%%%%bgColor%=%new%Color(bgColor.getRed(),% %
%% %bgColor.getGreen(), %
%%%% %bgColor.getBlue(),%255);%
%%%%%%%%%%%%%%%%w.setBackground(bgColor);%
%%%%%%%%%%%%}%
%%%%%%%%}%
…%
}%
This%code%in%
GraphicsDevice%uses%
more%methods%of%
Window%than%calling%
its%own%methods!%
“Feature
envy” smell
Focus on Design Smells
Initial Journal Paper
Published	in	Journal	of	Object	Technology	(Vol.	12,	No.	2,	2013)	
  S	G	Ganesh,	Tushar	Sharma,	Girish	Suryanarayana.		Towards	a	Principle-based	
Classifica4on	of	Structural	Design	Smells.		In	Journal	of	Object	Technology,	vol.	
12,	no.	2,	2013,	pages	1:1–29.doi:10.5381/jot.2013.12.2.a1	
  URL:	hLp://www.jot.fm/issues/issue_2013_06/arPcle1.pdf	(open	access)
… and a Conference Paper
Finally a Book
For Architects: Design is the Key!
Why Care About Principles?
Equivalent Principles in Software Design?
Architectural principles:
Axis, symmetry, rhythm, datum, hierarchy, transformation
Equivalent Principles in Software Design!
Principles*
Abstrac/on*
Encapsula/on*
Modulariza/on*
Hierarchy*
Proactive Application: Enabling Techniques
Reactive Application: Smells
Design Smells: Example #1
Discussion Example
Design Smells: Example #2
Discussion Example
Design Smells: Example #3
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?
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
IMPaCT Process Model
Refactoring: Practical concerns
“Fear of breaking
working code”
Is management buy-in necessary for refactoring?
How to refactor code in legacy projects (no automated
tests, difficulty in understanding, lack of motivation, …)?
Where do I have time
for refactoring?
“Applying design principles is the key to creating
high-quality software!”
Architectural principles:
Axis, symmetry, rhythm, datum, hierarchy, transformation
email sgganesh@gmail.com
website www.designsmells.com
twitter @GSamarthyam
linkedin bit.ly/sgganesh
slideshare slideshare.net/sgganesh

More Related Content

PDF
Tdd with python unittest for embedded c
PDF
A Evolucao dos Processos de Desenvolvimento de Software
PDF
Introduction to DevOps Tools | DevOps Training | DevOps Tutorial for Beginner...
PDF
Fast Flow & Organizational Evolution with Team Topologies @ Masters of Softwa...
PDF
Organiser son CI/CD - présentation
PDF
SAFe DevOps digital workbook (5.0)
PDF
webOS Introduction
PDF
Intro to Kubernetes
Tdd with python unittest for embedded c
A Evolucao dos Processos de Desenvolvimento de Software
Introduction to DevOps Tools | DevOps Training | DevOps Tutorial for Beginner...
Fast Flow & Organizational Evolution with Team Topologies @ Masters of Softwa...
Organiser son CI/CD - présentation
SAFe DevOps digital workbook (5.0)
webOS Introduction
Intro to Kubernetes

What's hot (20)

PPTX
Yazılım Gereksinim Mühendisliği Semineri
PDF
"DevOps > CI+CD "
PDF
AI/ML O-RAN Cloud-Native Automation
PPTX
Mule api management
PPTX
Jenkins - From Continuous Integration to Continuous Delivery
PDF
A GitOps Kubernetes Native CICD Solution with Argo Events, Workflows, and CD
PPTX
Transforming Organizations with CI/CD
PDF
Continuous Integration/Deployment with Gitlab CI
PPTX
Kubernetes introduction
PDF
Introducing GitLab (September 2018)
PPTX
Présentation de git
PPTX
12 factor app an introduction
PDF
Automotive embedded systems part2 v1
PPTX
DevOps concepts, tools, and technologies v1.0
PDF
JavaScript for Hackers.pdf
PDF
A/B Linux updates with RAUC and meta-rauc-community: now & in the future
PDF
Operator Framework Overview
PPTX
Git presentation
PDF
CNCF Webinar Series: "Creating an Effective Developer Experience on Kubernetes"
PPTX
Devops and git basics
Yazılım Gereksinim Mühendisliği Semineri
"DevOps > CI+CD "
AI/ML O-RAN Cloud-Native Automation
Mule api management
Jenkins - From Continuous Integration to Continuous Delivery
A GitOps Kubernetes Native CICD Solution with Argo Events, Workflows, and CD
Transforming Organizations with CI/CD
Continuous Integration/Deployment with Gitlab CI
Kubernetes introduction
Introducing GitLab (September 2018)
Présentation de git
12 factor app an introduction
Automotive embedded systems part2 v1
DevOps concepts, tools, and technologies v1.0
JavaScript for Hackers.pdf
A/B Linux updates with RAUC and meta-rauc-community: now & in the future
Operator Framework Overview
Git presentation
CNCF Webinar Series: "Creating an Effective Developer Experience on Kubernetes"
Devops and git basics
Ad

Similar to Refactoring for Software Design Smells (20)

PPT
Contemporary Software Engineering Practices Together With Enterprise
PPT
02 architectures in_context
KEY
Agile Architecture (MAE slides)
PDF
SOLID Principles and Design Patterns
PPT
Software Development in 21st Century
PDF
The Modern Software Architect
PPT
04 designing architectures
PDF
ContainerDayVietnam2016: Become a Cloud-native Developer
PDF
Clean architecture with asp.net core
PPTX
The Role of the Architect
PDF
Modern Agile Software Architecture
PDF
Drinking from the Stream: How to Use Messaging Platforms for Scalability & Pe...
PDF
Module 2 design patterns-2
PDF
Drinking from the Stream: How to Use Messaging Platforms for Scalability & Pe...
PPT
PDC+++ Module 2 Class 7
PPT
01 the big_idea
PPTX
Best Practices for Cross-Platform Native Applications
PDF
Why die a developer ? (programming to architecture)
PDF
Refactoring for Software Design Smells - Tech Talk
PDF
Refactoring for Software Design Smells - Tech Talk
Contemporary Software Engineering Practices Together With Enterprise
02 architectures in_context
Agile Architecture (MAE slides)
SOLID Principles and Design Patterns
Software Development in 21st Century
The Modern Software Architect
04 designing architectures
ContainerDayVietnam2016: Become a Cloud-native Developer
Clean architecture with asp.net core
The Role of the Architect
Modern Agile Software Architecture
Drinking from the Stream: How to Use Messaging Platforms for Scalability & Pe...
Module 2 design patterns-2
Drinking from the Stream: How to Use Messaging Platforms for Scalability & Pe...
PDC+++ Module 2 Class 7
01 the big_idea
Best Practices for Cross-Platform Native Applications
Why die a developer ? (programming to architecture)
Refactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech Talk
Ad

More from Ganesh Samarthyam (20)

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

Recently uploaded (20)

PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Nekopoi APK 2025 free lastest update
PDF
top salesforce developer skills in 2025.pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
L1 - Introduction to python Backend.pptx
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
medical staffing services at VALiNTRY
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
history of c programming in notes for students .pptx
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Essential Infomation Tech presentation.pptx
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
AI in Product Development-omnex systems
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
ai tools demonstartion for schools and inter college
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Odoo POS Development Services by CandidRoot Solutions
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Nekopoi APK 2025 free lastest update
top salesforce developer skills in 2025.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
L1 - Introduction to python Backend.pptx
Design an Analysis of Algorithms II-SECS-1021-03
How Creative Agencies Leverage Project Management Software.pdf
medical staffing services at VALiNTRY
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
history of c programming in notes for students .pptx
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Essential Infomation Tech presentation.pptx
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
AI in Product Development-omnex systems
Upgrade and Innovation Strategies for SAP ERP Customers
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
ai tools demonstartion for schools and inter college
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Odoo POS Development Services by CandidRoot Solutions

Refactoring for Software Design Smells