SlideShare uma empresa Scribd logo
1 de 48
Baixar para ler offline
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!

Mais conteúdo relacionado

Semelhante a 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
 

Semelhante a 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
 

Último

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Último (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Design smells