SlideShare a Scribd company logo
1 of 15
Bad Smells in
Code
CocoDojo
Duplicated Code
Extract out the common bits into theirown method
(extract method) if code is in same class if two classes
duplicate code, consider extract class to create a new
class to hold the shared functionality.
Long Method
extract method!
Large Class
Class trying to do too much often shows up
as too many instance variables.
Long Parameter
List
replace parameter with method (receiver explicitly asks
sender for data via sender getter method)
Example: day month, year, hour minute second ==> date
Divergent Change
If you have a fixed class that does distinctly different things
consider separating out the varying code into varying
classes (extract class) that either subclassor are contained
by the non-varying class.
Shotgun Surgery
The smell: a change in one class repeatedly requires little
changes in a bunch of other classes. try to move
method and move field to get all the bits into one class since
they areobviously highly dependent.
Feature Envy
Method in one class uses lots of pieces from another
class. move method to move it to the other class.
Data Clumps
Data that's always hanging with each other (e.g. name
street zip). Extract out a class (extract class) for the data.
Will help trim argument lists too since name street zip
now passed as one address object.
Primitive
Obsession
Switch Statements
Use inheritance and polymorphism instead
(example of this was in Fowler Chapter 1; this is one of
the more difficult refactorings)
Lazy Class
Speculative
Generality
Temporary Field
Message Chains

More Related Content

What's hot

java Method Overloading
java Method Overloadingjava Method Overloading
java Method Overloadingomkar bhagat
 
Classes & objects new
Classes & objects newClasses & objects new
Classes & objects newlykado0dles
 
Keyword of java
Keyword of javaKeyword of java
Keyword of javaJani Harsh
 
Classes, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaClasses, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaRadhika Talaviya
 
Inheritance and Polymorphism in java simple and clear
Inheritance and Polymorphism in java simple and clear Inheritance and Polymorphism in java simple and clear
Inheritance and Polymorphism in java simple and clear ASHNA nadhm
 
Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)Nuzhat Memon
 
9781439035665 ppt ch08
9781439035665 ppt ch089781439035665 ppt ch08
9781439035665 ppt ch08Terry Yoast
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and objectFajar Baskoro
 
Logic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing ApplicationsLogic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing Applicationskjkleindorfer
 
Static keyword ppt
Static keyword pptStatic keyword ppt
Static keyword pptVinod Kumar
 
Intercepting Filters Design Pattern
Intercepting Filters Design PatternIntercepting Filters Design Pattern
Intercepting Filters Design PatternProdigyView
 
Introduction to method overloading & method overriding in java hdm
Introduction to method overloading & method overriding  in java  hdmIntroduction to method overloading & method overriding  in java  hdm
Introduction to method overloading & method overriding in java hdmHarshal Misalkar
 

What's hot (20)

Method overloading
Method overloadingMethod overloading
Method overloading
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
4. method overloading
4. method overloading4. method overloading
4. method overloading
 
java Method Overloading
java Method Overloadingjava Method Overloading
java Method Overloading
 
Classes & objects new
Classes & objects newClasses & objects new
Classes & objects new
 
Keyword of java
Keyword of javaKeyword of java
Keyword of java
 
Classes, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaClasses, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with Java
 
Inheritance and Polymorphism in java simple and clear
Inheritance and Polymorphism in java simple and clear Inheritance and Polymorphism in java simple and clear
Inheritance and Polymorphism in java simple and clear
 
Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)
 
Java constructors
Java constructorsJava constructors
Java constructors
 
9781439035665 ppt ch08
9781439035665 ppt ch089781439035665 ppt ch08
9781439035665 ppt ch08
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and object
 
Logic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing ApplicationsLogic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing Applications
 
Abstract classes
Abstract classesAbstract classes
Abstract classes
 
Static keyword ppt
Static keyword pptStatic keyword ppt
Static keyword ppt
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Intercepting Filters Design Pattern
Intercepting Filters Design PatternIntercepting Filters Design Pattern
Intercepting Filters Design Pattern
 
Introduction to method overloading & method overriding in java hdm
Introduction to method overloading & method overriding  in java  hdmIntroduction to method overloading & method overriding  in java  hdm
Introduction to method overloading & method overriding in java hdm
 
StringTokenizer in java
StringTokenizer in javaStringTokenizer in java
StringTokenizer in java
 
11. java methods
11. java methods11. java methods
11. java methods
 

Similar to Bad smells in code

Similar to Bad smells in code (20)

Code Refactoring
Code RefactoringCode Refactoring
Code Refactoring
 
Bad Smells in Code
Bad Smells in CodeBad Smells in Code
Bad Smells in Code
 
Bad Smell In Codes 1
Bad Smell In Codes 1Bad Smell In Codes 1
Bad Smell In Codes 1
 
Refactoring bad codesmell
Refactoring bad codesmellRefactoring bad codesmell
Refactoring bad codesmell
 
Code smells
Code smellsCode smells
Code smells
 
Bade Smells in Code
Bade Smells in CodeBade Smells in Code
Bade Smells in Code
 
Bad Smell in Codes - Part 1
Bad Smell in Codes - Part 1Bad Smell in Codes - Part 1
Bad Smell in Codes - Part 1
 
E3
E3E3
E3
 
Oops
OopsOops
Oops
 
Chapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIChapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part II
 
Oops
OopsOops
Oops
 
Java căn bản - Chapter7
Java căn bản - Chapter7Java căn bản - Chapter7
Java căn bản - Chapter7
 
Ruby object model
Ruby object modelRuby object model
Ruby object model
 
Refactoring
RefactoringRefactoring
Refactoring
 
06 InheritanceAndPolymorphism.ppt
06 InheritanceAndPolymorphism.ppt06 InheritanceAndPolymorphism.ppt
06 InheritanceAndPolymorphism.ppt
 
Review oop and ood
Review oop and oodReview oop and ood
Review oop and ood
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
oops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdfoops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdf
 
C#
C#C#
C#
 
Core java by amit
Core java by amitCore java by amit
Core java by amit
 

More from Đới Học viện Agile

Quản lí nhóm làm việc ở nhà - phiên bản 1
Quản lí nhóm làm việc ở nhà - phiên bản 1Quản lí nhóm làm việc ở nhà - phiên bản 1
Quản lí nhóm làm việc ở nhà - phiên bản 1Đới Học viện Agile
 
Cách xây dựng nhóm phần mềm hiệu năng cao
Cách xây dựng nhóm phần mềm hiệu năng caoCách xây dựng nhóm phần mềm hiệu năng cao
Cách xây dựng nhóm phần mềm hiệu năng caoĐới Học viện Agile
 
How to release every week? Case study of Continuous Integration from VNDirect
How to release every week? Case study of Continuous Integration from VNDirectHow to release every week? Case study of Continuous Integration from VNDirect
How to release every week? Case study of Continuous Integration from VNDirectĐới Học viện Agile
 
[XP Day Vietnam 2015] What makes software flexible
[XP Day Vietnam 2015] What makes software flexible[XP Day Vietnam 2015] What makes software flexible
[XP Day Vietnam 2015] What makes software flexibleĐới Học viện Agile
 
Agile adoption for Higher Education & Training Center in companies
Agile adoption for Higher Education & Training Center in companiesAgile adoption for Higher Education & Training Center in companies
Agile adoption for Higher Education & Training Center in companiesĐới Học viện Agile
 
Phát triển hướng hành vi - Behavior Driven Development - BDD
Phát triển hướng hành vi - Behavior Driven Development - BDDPhát triển hướng hành vi - Behavior Driven Development - BDD
Phát triển hướng hành vi - Behavior Driven Development - BDDĐới Học viện Agile
 
Động viên từng sinh viên với học tập đảo ngược
Động viên từng sinh viên với học tập đảo ngượcĐộng viên từng sinh viên với học tập đảo ngược
Động viên từng sinh viên với học tập đảo ngượcĐới Học viện Agile
 
A path to transform into agile in vietnamese culture
A path to transform into agile in vietnamese cultureA path to transform into agile in vietnamese culture
A path to transform into agile in vietnamese cultureĐới Học viện Agile
 

More from Đới Học viện Agile (20)

Quản lí nhóm làm việc ở nhà - phiên bản 1
Quản lí nhóm làm việc ở nhà - phiên bản 1Quản lí nhóm làm việc ở nhà - phiên bản 1
Quản lí nhóm làm việc ở nhà - phiên bản 1
 
Agile trong dự án fixed price case study
Agile trong dự án fixed price case studyAgile trong dự án fixed price case study
Agile trong dự án fixed price case study
 
Agile trong dự án fixed price
Agile trong dự án fixed priceAgile trong dự án fixed price
Agile trong dự án fixed price
 
How to start your agile journey
How to start your agile journeyHow to start your agile journey
How to start your agile journey
 
How to pay people?
How to pay people?How to pay people?
How to pay people?
 
Ngụy biện - fallacy
Ngụy biện - fallacyNgụy biện - fallacy
Ngụy biện - fallacy
 
Cách xây dựng nhóm phần mềm hiệu năng cao
Cách xây dựng nhóm phần mềm hiệu năng caoCách xây dựng nhóm phần mềm hiệu năng cao
Cách xây dựng nhóm phần mềm hiệu năng cao
 
Coach using facilitation
Coach using facilitationCoach using facilitation
Coach using facilitation
 
Being agile with your outsourcing partner
Being agile with your outsourcing partnerBeing agile with your outsourcing partner
Being agile with your outsourcing partner
 
How to build your first agile team
How to build your first agile teamHow to build your first agile team
How to build your first agile team
 
How to release every week? Case study of Continuous Integration from VNDirect
How to release every week? Case study of Continuous Integration from VNDirectHow to release every week? Case study of Continuous Integration from VNDirect
How to release every week? Case study of Continuous Integration from VNDirect
 
[XP Day Vietnam 2015] What makes software flexible
[XP Day Vietnam 2015] What makes software flexible[XP Day Vietnam 2015] What makes software flexible
[XP Day Vietnam 2015] What makes software flexible
 
[XP Day Vietnam 2015] XP is not windows XP
[XP Day Vietnam 2015] XP is not windows XP[XP Day Vietnam 2015] XP is not windows XP
[XP Day Vietnam 2015] XP is not windows XP
 
Agile adoption for Higher Education & Training Center in companies
Agile adoption for Higher Education & Training Center in companiesAgile adoption for Higher Education & Training Center in companies
Agile adoption for Higher Education & Training Center in companies
 
Phát triển hướng hành vi - Behavior Driven Development - BDD
Phát triển hướng hành vi - Behavior Driven Development - BDDPhát triển hướng hành vi - Behavior Driven Development - BDD
Phát triển hướng hành vi - Behavior Driven Development - BDD
 
Động viên từng sinh viên với học tập đảo ngược
Động viên từng sinh viên với học tập đảo ngượcĐộng viên từng sinh viên với học tập đảo ngược
Động viên từng sinh viên với học tập đảo ngược
 
A path to transform into agile in vietnamese culture
A path to transform into agile in vietnamese cultureA path to transform into agile in vietnamese culture
A path to transform into agile in vietnamese culture
 
Học tập đảo ngược
Học tập đảo ngượcHọc tập đảo ngược
Học tập đảo ngược
 
Code retreat agile tour 2013
Code retreat agile tour 2013Code retreat agile tour 2013
Code retreat agile tour 2013
 
Introduction to summer coderetreat 2013
Introduction to summer coderetreat 2013Introduction to summer coderetreat 2013
Introduction to summer coderetreat 2013
 

Recently uploaded

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 

Recently uploaded (20)

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 

Bad smells in code