SlideShare ist ein Scribd-Unternehmen logo
1 von 48
Downloaden Sie, um offline zu lesen
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!

Weitere ähnliche Inhalte

Ähnlich wie Design smells

Writting Better Software
Writting Better SoftwareWritting Better Software
Writting Better Software
svilen.ivanov
 
Report
ReportReport
Report
butest
 
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
 
Best practices in enterprise applications
Best practices in enterprise applicationsBest practices in enterprise applications
Best practices in enterprise applications
Chandra Sekhar Saripaka
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
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
 
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...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Design smells