SlideShare une entreprise Scribd logo
1  sur  48
Télécharger pour lire hors ligne
Design smells
Design smells taxonomy
✤ Bloaters
✤ Object-Orientation Abusers
✤ Change Preventers
✤ Dispensables
✤ Couplers
Bloaters
Bloaters
Bloaters are code, methods and classes
that have increased to such gargantuan
proportions that they are hard to work
with. Usually these smells do not crop up
right away, rather they accumulate over
time as the program evolves (and
especially when nobody makes an effort
to eradicate them).
Bloaters
✤ Long method
✤ Large class
✤ Long parameter list
✤ Primitive obsession
✤ Data clumps
Long Method (1/5)
Signs and Symptoms
Large number of lines
Long Method (1/5)
Reasons for the Problem
“Columbo syndrome”, was the detective who always
had “just one more thing”.

"But it's just two lines, there's no use in creating a whole
method just for that..."
Long Method (1/5)
Treatment
✤ Use Extract Method to break up the method into smaller pieces

✤ If local variables and parameters interfere with extracting a method,
use Replace Temp with Query, Introduce Parameter Object or
Preserve Whole Object.

✤ If none of the previous recipes help, try moving the entire method to a
separate object via Replace Method with Method Object.

✤ Conditional operators and loops are a good clue that code can be
moved to a separate method. For conditionals, use Decompose
Conditional. If loops are in the way, try Extract Method.
Long Method (1/5)
Payoff
✤Improves communication

✤May expose duplication

✤Often helps new classes and abstractions emerge
Long Method (1/5)
Performance
Now that you have clear and understandable code, you
are more likely to find truly effective methods for
restructuring code and getting real performance gains if
the need ever arises
Large Class (2/5)
Signs and Symptoms
A class contains many fields/methods/lines of code.
Large Class (2/5)
Reasons for the Problem
Classes usually start small. But over time, they get
bloated as the program grows.

As is the case with long methods as well, programmers
usually find it mentally less taxing to place a new feature
in an existing class than to create a new class for the
feature.
Large Class (2/5)
Treatment
✤ Extract Class helps if part of the behavior of the large class can be spun off
into a separate component.

✤ Extract Subclass helps if part of the behavior of the large class can be
implemented in different ways or is used in rare cases.

✤ Extract Interface helps if it is necessary to have a list of the operations and
behaviors that the client can use.

✤ If a large class is responsible for the graphical interface, you may try to move
some of its data and behavior to a separate domain object. In doing so, it
may be necessary to store copies of some data in two places and keep the
data consistent. Duplicate Observed Data offers a way to do this.
Large Class (2/5)
Payoff
✤Refactoring of these classes spares developers from
needing to remember a large number of attributes for a
class.

✤In many cases, splitting large classes into parts avoids
duplication of code and functionality.
Long Parameter List (3/5)
Signs and Symptoms
More than three or four parameters for a method.
Long Parameter List (3/5)
Reasons for the Problem
xxx
Long Parameter List (3/5)
Treatment
xxx
Long Parameter List (3/5)
Payoff
xxx
Long Parameter List (3/5)
Performance
xxx
Primitive Obsession (4/5)
Signs and Symptoms
Use of primitives instead of small objects for simple tasks (such
as currency, ranges, special strings for phone numbers, etc.)

Use of constants for coding information (such as a constant
USER_ADMIN_ROLE = 1 for referring to users with
administrator rights.)

Use of string constants as field names for use in data arrays.
Primitive Obsession (4/5)
Reasons for the Problem
xxx
Primitive Obsession (4/5)
Treatment
xxx
Primitive Obsession (4/5)
Payoff
xxx
Primitive Obsession (4/5)
Performance
xxx
Data Clumps (5/5)
Signs and Symptoms
Sometimes different parts of the code contain identical
groups of variables (such as parameters for connecting
to a database). These clumps should be turned into their
own classes.
Data Clumps (5/5)
Reasons for the Problem
xxx
Data Clumps (5/5)
Treatment
xxx
Data Clumps (5/5)
Payoff
xxx
Data Clumps (5/5)
Performance
xxx
Some examples
Object-oriented abusers
Object-
Orientation
Abusers
All these smells are incomplete or
incorrect application of object-oriented
programming principles.
Object-Orientation Abusers
✤ Switch statements
✤ Refused bequest
✤ Temporary field
✤ Alternative classes with different interfaces
Some examples
Change preventers
Change
preventers
These smells mean that if you need to
change something in one place in your
code, you have to make many changes in
other places too. Program development
becomes much more complicated and
expensive as a result
Change preventers
✤ Divergent change
✤ Parallel inheritance hierarchies
✤ Shotgun surgery
Some examples
Dispensables
Dispensables
A dispensable is something pointless and
unneeded whose absence would make the
code cleaner, more efficient and easier to
understand
Dispensables
✤ Comments
✤ Duplicate code
✤ Lazy class
✤ Data class
✤ Dead code
✤ Speculative generality
Some examples
Couplers
Couplers
All the smells in this group contribute to
excessive coupling between classes or
show what happens if coupling is
replaced by excessive delegation
Couplers
✤ Feature envy
✤ Inappropriate intimacy
✤ Message chains
✤ Middle man
✤ Incomplete library class
Some examples
Questions?
Zankiu!

Contenu connexe

Similaire à Design smells

Writting Better Software
Writting Better SoftwareWritting Better Software
Writting Better Softwaresvilen.ivanov
 
Top 10 Data Science Practitioner Pitfalls
Top 10 Data Science Practitioner PitfallsTop 10 Data Science Practitioner Pitfalls
Top 10 Data Science Practitioner PitfallsSri Ambati
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataCory Foy
 
Programming with C++
Programming with C++Programming with C++
Programming with C++ssuser802d47
 
Code Smells - Refactoring
Code Smells - RefactoringCode Smells - Refactoring
Code Smells - RefactoringShobi P P
 
Code Smells and Its type (With Example)
Code Smells and Its type (With Example)Code Smells and Its type (With Example)
Code Smells and Its type (With Example)Anshul Vinayak
 
Introduction to programming by MUFIX Commnity
Introduction to programming by MUFIX CommnityIntroduction to programming by MUFIX Commnity
Introduction to programming by MUFIX Commnitymazenet
 
Report
ReportReport
Reportbutest
 
Lecture 9 slides: Machine learning for Protein Structure ...
Lecture 9 slides: Machine learning for Protein Structure ...Lecture 9 slides: Machine learning for Protein Structure ...
Lecture 9 slides: Machine learning for Protein Structure ...butest
 
Hand Coding ETL Scenarios and Challenges
Hand Coding ETL Scenarios and ChallengesHand Coding ETL Scenarios and Challenges
Hand Coding ETL Scenarios and Challengesmark madsen
 
Best practices in enterprise applications
Best practices in enterprise applicationsBest practices in enterprise applications
Best practices in enterprise applicationsChandra Sekhar Saripaka
 

Similaire à Design smells (20)

Bad Smells in Code
Bad Smells in CodeBad Smells in Code
Bad Smells in Code
 
Code Metrics
Code MetricsCode Metrics
Code Metrics
 
Refactoring
RefactoringRefactoring
Refactoring
 
Writting Better Software
Writting Better SoftwareWritting Better Software
Writting Better Software
 
Template pattern
Template patternTemplate pattern
Template pattern
 
Top 10 Data Science Practitioner Pitfalls
Top 10 Data Science Practitioner PitfallsTop 10 Data Science Practitioner Pitfalls
Top 10 Data Science Practitioner Pitfalls
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and Data
 
Programming with C++
Programming with C++Programming with C++
Programming with C++
 
Code Smells - Refactoring
Code Smells - RefactoringCode Smells - Refactoring
Code Smells - Refactoring
 
Dealing With Time In System Dynamics Models
Dealing With Time In System Dynamics ModelsDealing With Time In System Dynamics Models
Dealing With Time In System Dynamics Models
 
Max diff
Max diffMax diff
Max diff
 
Code Smells and Its type (With Example)
Code Smells and Its type (With Example)Code Smells and Its type (With Example)
Code Smells and Its type (With Example)
 
Ase02 dmp.ppt
Ase02 dmp.pptAse02 dmp.ppt
Ase02 dmp.ppt
 
Introduction To Programming (2009 2010)
Introduction To Programming (2009 2010)Introduction To Programming (2009 2010)
Introduction To Programming (2009 2010)
 
Introduction to programming by MUFIX Commnity
Introduction to programming by MUFIX CommnityIntroduction to programming by MUFIX Commnity
Introduction to programming by MUFIX Commnity
 
Refactoring
RefactoringRefactoring
Refactoring
 
Report
ReportReport
Report
 
Lecture 9 slides: Machine learning for Protein Structure ...
Lecture 9 slides: Machine learning for Protein Structure ...Lecture 9 slides: Machine learning for Protein Structure ...
Lecture 9 slides: Machine learning for Protein Structure ...
 
Hand Coding ETL Scenarios and Challenges
Hand Coding ETL Scenarios and ChallengesHand Coding ETL Scenarios and Challenges
Hand Coding ETL Scenarios and Challenges
 
Best practices in enterprise applications
Best practices in enterprise applicationsBest practices in enterprise applications
Best practices in enterprise applications
 

Dernier

Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?IES VE
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesDavid Newbury
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfJamie (Taka) Wang
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxGDSC PJATK
 

Dernier (20)

Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?
 
20150722 - AGV
20150722 - AGV20150722 - AGV
20150722 - AGV
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond Ontologies
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptx
 

Design smells