SlideShare a Scribd company logo
Refactoring for
Software Design Smells
Ganesh Samarthyam
Entrepreneur; author; speaker
ganesh@codeops.tech
www.codeops.tech
–Craig Larman
"The critical design tool for software development
is a mind well educated in design principles"
Poor software quality costs
more than $150 billion per year
in U.S. and greater than $500
billion per year worldwide
- Capers Jones
Source: Estimating the Principal of an Application's Technical Debt, Bill Curtis, Jay
Sappidi, Alexandra Szynkarski, IEEE Software, Nov.-Dec. 2012.
Source: Consortium of IT Software Quality (CISQ), Bill Curtis, Architecturally Complex Defects, 2012
“The problem with quick and dirty...is that dirty
remains long after quick has been forgotten”
Steve C McConnell
For Architects: Design is the Key!
Refactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech Talk
"... a delightful, engaging, actionable read... you have
in your hand a veritable field guide of smells... one
of the more interesting and complex expositions of
software smells you will ever find..."
- From the foreword by Grady Booch (IBM Fellow and Chief Scientist for
Software Engineering, IBM Research)
"This is a good book about ‘Design Smells’ – actually
a great book – nicely organized - clearly written with
plenty of examples and a fair sprinkling of
anecdotes."
- Will Tracz (Principal Research Scientist & Fellow, Lockheed Martin)
(review in ACM SIGSOFT Software Engineering Notes)
Fundamental Principles in Software Design
Principles*
Abstrac/on*
Encapsula/on*
Modulariza/on*
Hierarchy*
Proactive Application: Enabling Techniques
Reactive Application: Smells
Is this a Smell?
abstract class Printer {
private Integer portNumber = getPortNumber();
abstract Integer getPortNumber();
public static void main(String[]s) {
Printer p = new LPDPrinter();
System.out.println(p.portNumber);
}
}
class LPDPrinter extends Printer {
/* Line Printer Deamon port no is 515 */
private Integer defaultPortNumber = 515;
Integer getPortNumber() {
return defaultPortNumber;
}
}
prints
“null”!
What’s that smell?
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'AbstractBuEon)'{'
'''''''''''''''''margin'='((AbstractBuEon)c).getMargin();'
''''''''}'else'if'(c'instanceof'JToolBar)'{'
''''''''''''''''margin'='((JToolBar)c).getMargin();'
''''''''}'else'if'(c'instanceof'JTextComponent)'{'
''''''''''''''''margin'='((JTextComponent)c).getMargin();'
''''''''}'
''''''''//'rest'of'the'code'omiEed'…'
Refactoring
Refactoring
!!!!!!!margin!=!c.getMargin();
!!!!!!!!if!(c!instanceof!AbstractBu8on)!{!
!!!!!!!!!!!!!!!!!margin!=!((AbstractBu8on)c).getMargin();!
!!!!!!!!}!else!if!(c!instanceof!JToolBar)!{!
!!!!!!!!!!!!!!!!margin!=!((JToolBar)c).getMargin();!
!!!!!!!!}!else!if!(c!instanceof!JTextComponent)!{!
!!!!!!!!!!!!!!!!margin!=!((JTextComponent)c).getMargin();!
!!!!!!!!}
Design Smells: Example
Discussion Example
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?
Liskov’s Substitution Principle (LSP)
It#should#be#possible#to#replace#
objects#of#supertype#with#
objects#of#subtypes#without#
altering#the#desired#behavior#of#
the#program#
Barbara#Liskov#
Refactoring
Replace inheritance
with delegation
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);'
}'
Replace conditional with polymorphism
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);(
}!
Configuration Smells!
Language Features & Refactoring
public static void main(String []file) throws Exception {
// process each file passed as argument
// try opening the file with FileReader
try (FileReader inputFile = new FileReader(file[0])) {
int ch = 0;
while( (ch = inputFile.read()) != -1) {
// ch is of type int - convert it back to char
System.out.print( (char)ch );
}
}
// try-with-resources will automatically release FileReader object
}
public static void main(String []file) throws Exception {
Files.lines(Paths.get(file[0])).forEach(System.out::println);
}
Java 8 lambdas and streams
Refactoring Windows!
Refactoring Windows!
“A large number of dependencies at the module level
could be reduced and optimized to:
* make modular reasoning of the system more efficient
* maximize parallel development efficiency
* avoid unwanted parallel change interference
* selectively rebuild and retest subsystems effectively”
Refactoring performed to reduce
and optimize dependencies - by
creating and enforcing layering
Source: Kim, Miryung, Thomas Zimmermann, and Nachiappan Nagappan. "An Empirical Study of RefactoringChallenges and Benefits at Microsoft."
IEEE Transactions on Software Engineering 7 (2014): 1-1.
Refactoring Windows!
Refactoring decisions made after substantial
analysis of existing dependency structure
Refactoring effort was centralized and top
down with designated team for refactoring
Use of custom refactoring tools (MaX)
and processes (quality gate check)
Source: Kim, Miryung, Thomas Zimmermann, and Nachiappan Nagappan. "An Empirical Study of RefactoringChallenges and Benefits at Microsoft."
IEEE Transactions on Software Engineering 7 (2014): 1-1.
Tangles in
JDK
Refactoring for Software Design Smells - Tech Talk
Copyright © 2015, Oracle and/or its affiliates. All rights reserved
Copyright © 2015, Oracle and/or its affiliates. All rights reserved
Structural Analysis for Java (stan4j)
JArchitect
InFusion
SotoArc
CodeCity
Name the first
object oriented
programming
language
Which pattern is this?
a)	Bridge	pa+ern		
b)	Decorator	pa+ern		
c)	Builder	pa+ern			
d)	Strategy	pa+ern	
LineNumberReader lnr =
new LineNumberReader(
new BufferedReader(
new FileReader(“./test.c")));
String str = null;
while((str = lnr.readLine()) != null)
System.out.println(lnr.getLineNumber() + ": " + str);
Decorator pattern in Reader
Who coined the
term “code
smell”?
Meetups
h+p://www.meetup.com/JavaScript-Meetup-Bangalore/	
h+p://www.meetup.com/Container-Developers-Meetup-Bangalore/		
h+p://www.meetup.com/SoBware-CraBsmanship-Bangalore-Meetup/	
h+p://www.meetup.com/Core-Java-Meetup-Bangalore/	
h+p://www.meetup.com/Technical-Writers-Meetup-Bangalore/	
h+p://www.meetup.com/CloudOps-Meetup-Bangalore/	
h+p://www.meetup.com/Bangalore-SDN-IoT-NetworkVirtualizaKon-Enthusiasts/	
h+p://www.meetup.com/SoBwareArchitectsBangalore/
Upcoming Java 8 Bootcamp
Modern Programming with Java 8
Refactor your legacy applications using Java 8 features
Register here: https://www.townscript.com/e/java8-refactoring
ganesh@codeops.tech @GSamarthyam
www.codeops.tech slideshare.net/sgganesh
+91 98801 64463 bit.ly/ganeshsg

More Related Content

PDF
Refactoring for Software Design Smells
PDF
OO Design and Design Patterns in C++
PDF
Applying Design Patterns in Practice
PPT
Design poo my_jug_en_ppt
PPTX
About Dewey Hong
PDF
Software Architecture - Quiz Questions
PDF
On Impact in Software Engineering Research
PPT
Six Principles of Software Design to Empower Scientists
Refactoring for Software Design Smells
OO Design and Design Patterns in C++
Applying Design Patterns in Practice
Design poo my_jug_en_ppt
About Dewey Hong
Software Architecture - Quiz Questions
On Impact in Software Engineering Research
Six Principles of Software Design to Empower Scientists

What's hot (20)

PPTX
Software design principles
PPTX
Software Craftsmanship VS Software Engineering
PDF
Clean Software Design: The Practices to Make The Design Simple
PDF
Applying Design Principles in Practice
PDF
Refactoring for Software Architecture Smells - International Workshop on Refa...
PDF
Waste Driven Development - Agile Coaching Serbia Meetup
PDF
Sandro Mancuso - Software Craftmanship @ I T.A.K.E. Unconference 2013, Bucharest
PPTX
Open Source Data Annotation Platform for NLP, CV, Tabular, and Log Data
PDF
Feedback on Part 1 of the Software Engineering Large Practical
PDF
Worse is better, for better or for worse - Kevlin Henney
PPT
Fp201 unit1 1
PPTX
DDT Testing Library for Android
PDF
My Career Journey: An Unconventional Path into DevOps
PPT
Design Smells
PDF
Java Design Patterns Tutorial | Edureka
PPTX
Importance of the quality of code
PDF
Feedback on Part 1 of the CSLP
PDF
Opposites Attract
PDF
Solid principles of oo design
PDF
Understanding, measuring and improving code quality in JavaScript
Software design principles
Software Craftsmanship VS Software Engineering
Clean Software Design: The Practices to Make The Design Simple
Applying Design Principles in Practice
Refactoring for Software Architecture Smells - International Workshop on Refa...
Waste Driven Development - Agile Coaching Serbia Meetup
Sandro Mancuso - Software Craftmanship @ I T.A.K.E. Unconference 2013, Bucharest
Open Source Data Annotation Platform for NLP, CV, Tabular, and Log Data
Feedback on Part 1 of the Software Engineering Large Practical
Worse is better, for better or for worse - Kevlin Henney
Fp201 unit1 1
DDT Testing Library for Android
My Career Journey: An Unconventional Path into DevOps
Design Smells
Java Design Patterns Tutorial | Edureka
Importance of the quality of code
Feedback on Part 1 of the CSLP
Opposites Attract
Solid principles of oo design
Understanding, measuring and improving code quality in JavaScript
Ad

Viewers also liked (20)

PDF
Big code refactoring with agility
PDF
Refactoring: Improve the design of existing code
PDF
Overcoming the fear of deployments
PDF
Continuous Visual Integration - RailsConf 2016 - Mike Fotinakis - Percy.io
PPTX
Entregas Contínuas com feature toggles
PDF
Who will test your tests?
PPTX
Pull requests and testers can be friends
PDF
Continuous Integration, Delivery and Deployment
PPTX
Why we used Feature Branching
PPTX
Requirement and Test for Continuous Delivery - Customer in focus at Scania Co...
PDF
Trunk Based Development (CBSoft 2011)
PDF
Feature Toggle Examples
PDF
Feature Flags Are Flawed: Let's Make Them Better
PPTX
Strategies in continuous delivery
PPTX
Feature Flagging to Reduce Risk in Database Migrations
PPTX
Feature Toggles
PDF
Feature flags to speed up & de risk development
PDF
Test Automation
PPTX
Feature Toggle XP Conference 2016 Kalpana Gulati
PDF
Multiple projects, different goals, one thing in common: the codebase!
Big code refactoring with agility
Refactoring: Improve the design of existing code
Overcoming the fear of deployments
Continuous Visual Integration - RailsConf 2016 - Mike Fotinakis - Percy.io
Entregas Contínuas com feature toggles
Who will test your tests?
Pull requests and testers can be friends
Continuous Integration, Delivery and Deployment
Why we used Feature Branching
Requirement and Test for Continuous Delivery - Customer in focus at Scania Co...
Trunk Based Development (CBSoft 2011)
Feature Toggle Examples
Feature Flags Are Flawed: Let's Make Them Better
Strategies in continuous delivery
Feature Flagging to Reduce Risk in Database Migrations
Feature Toggles
Feature flags to speed up & de risk development
Test Automation
Feature Toggle XP Conference 2016 Kalpana Gulati
Multiple projects, different goals, one thing in common: the codebase!
Ad

Similar to Refactoring for Software Design Smells - Tech Talk (20)

PDF
Refactoring for Software Design Smells - Tech Talk
PDF
Refactoring for Software Design Smells - Tech Talk
PDF
Achieving Design Agility by Refactoring Design Smells
PDF
Refactoring for Software Design Smells - 1 day Workshop
PDF
Refactoring for Design Smells - ICSE 2014 Tutorial
PPTX
Refactoring for design smells
PDF
Refactoring guided by design principles driven by technical debt
PDF
Does your design smell - Tushar Sharma
PDF
Refactoring for software design smells - icse 2014 tutorial
DOCX
A Study on Code Smell Detection with Refactoring Tools in Object Oriented Lan...
PDF
Refactoring for Software Design smells - XP Conference - August 20th 2016
PDF
Refactoring for software design smells XP Conference 2016 Ganesh Samarthyam...
PDF
Refactoring for Software Design Smells - XP Conference - August 20th 2016
PPTX
Code smell overview
PDF
PDF
PDF
Msr17a.ppt
PDF
Code smells
PDF
Introduction to SOLID Principles
PDF
Tools for refactoring
Refactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech Talk
Achieving Design Agility by Refactoring Design Smells
Refactoring for Software Design Smells - 1 day Workshop
Refactoring for Design Smells - ICSE 2014 Tutorial
Refactoring for design smells
Refactoring guided by design principles driven by technical debt
Does your design smell - Tushar Sharma
Refactoring for software design smells - icse 2014 tutorial
A Study on Code Smell Detection with Refactoring Tools in Object Oriented Lan...
Refactoring for Software Design smells - XP Conference - August 20th 2016
Refactoring for software design smells XP Conference 2016 Ganesh Samarthyam...
Refactoring for Software Design Smells - XP Conference - August 20th 2016
Code smell overview
Msr17a.ppt
Code smells
Introduction to SOLID Principles
Tools for refactoring

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
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
PDF
Advanced Debugging Using Java Bytecodes
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)
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
Advanced Debugging Using Java Bytecodes

Recently uploaded (20)

PPTX
history of c programming in notes for students .pptx
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
System and Network Administration Chapter 2
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
AI in Product Development-omnex systems
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PPT
Introduction Database Management System for Course Database
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Introduction to Artificial Intelligence
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
history of c programming in notes for students .pptx
Upgrade and Innovation Strategies for SAP ERP Customers
System and Network Administration Chapter 2
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
AI in Product Development-omnex systems
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Design an Analysis of Algorithms II-SECS-1021-03
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
ManageIQ - Sprint 268 Review - Slide Deck
Introduction Database Management System for Course Database
Understanding Forklifts - TECH EHS Solution
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
CHAPTER 2 - PM Management and IT Context
Softaken Excel to vCard Converter Software.pdf
Introduction to Artificial Intelligence
VVF-Customer-Presentation2025-Ver1.9.pptx
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Navsoft: AI-Powered Business Solutions & Custom Software Development

Refactoring for Software Design Smells - Tech Talk