SlideShare a Scribd company logo
Anand Bait
Developer
Allerin Tech Pvt Ltd
Refactoring Code
 Making code better, may not be faster
 Better structured, better built
 More readable, more understandable
 Easy to work with
 Easy to add new features
 Easy to spot and fix bugs
 Keeping code in control
 Improving existing code
Contents
 Introduction to Refactoring
 Method-Level Refactoring
 Class and Condition Focused Refactoring
 Data Focused Refactoring
 Communication and High Level Refactoring
 Conclusion
What ‘REFACTORING’ is?
 Techniques of improving code that already exists
 No rules that anyone can blindly follow to improve
code
 Techniques of recognize issues as per consciousness
 Applied without thinking will be dangerous
What ‘REFACTORING’ is NOT?
 Not debugging
 Not adding feature
 Not changing observable behavior of code
 Not performance improving
Why to use?
When to use?
 Write – Scan – Refactor at the end : INCORRECT
 Write – Scan – Refactor regularly : CORRECT
 Code reviews
How to use?
Code smell
 Duplicated code
 Long methods
 Comments
 Doesn’t tell what to do but tells us what to notice
Method Level Refactoring
 Preparing to refactor
 Grouping refactorings together
 Using the Extract Method refactoring
 Extract Method with parameters and variables
 Common code smells for Extract Method
 Using IDEs for the Extract Method refactoring
 The Inline Method refactoring
 Refactorings that remove temps
 Refactorings that add temps
Preparing to refactor
 Requirement of automated testing vs manual testing
Grouping refactorings together
 Individual Method(name? parameters? Temp
variables? Duplicate? Too much in method?)
 Context of method in class (right class? similarity with
other methods class)
 Communication between classes(inheritance)
Extract Method refactoring
 Smaller and specific is better
 Provides reusability
 Ease of overriding while using inheritance
Extract Method with parameters
 Parameters should be related to the method
Extract Method with variables
 Temporary variables can be extracted
Code smells for using Extract
Method
 Long method
 Comments(having comments vs need comments)
Inline Method refactoring
 Removing method that adds no value
Refactoring to remove temps
 Increase temptation to write longer methods
 Change temps to small methods
Refactoring to add temps
 Split temporary variables
 Introduce explaining variables
 Remove assignments to parameters
Split temporary variables
 Don’t use same temporary variable for different
purposes
Introduce explaining variables
 To improve readability
 Introduce when a small method may not be required
Remove assignments to
parameters
 Add temporary variables that assigns value to
parameters may give undesired results
Class and Condition Focused
Refactoring
 Move Method
 Extract Class and Inline Class
 Making conditions easier to read
 Replacing conditions with polymorphism
 Replacing type code with subclasses
Move Method
 Move method from one class to another
 When a method interact with multiple classes then
move it to the class with which it interacts more
 Code smell: feature envy, inappropriate intimacy,
shotgun surgery
Extract Class and Inline Class
 Code smell: Large class
Making conditions easier to read
 Decompose conditionals
 Consolidate conditionals
 Consolidate duplicate conditionals
Replacing conditions with
polymorphism
 Conditions to check custom behavior
Replacing type code with
subclasses
 Data can be categorized into subclasses
Data Focused Refactoring
 Moving and encapsulating fields
 Working with data clumps
 Simplifying method calls and parameter use
 Pulling and pushing methods and fields
Moving and encapsulating fields
 If a field is more related and being used by the other
class
Working with data clumps
 Preserve whole object
(instead of parameters pass object)
 Introduce parameter object
(minimize parameters list by creating a class for set of
parameters)
Simplifying method calls and
parameter use
 Rename method
 Remove parameter
 Add parameter
 Parameterize method
(same behavior multiple methods)
 De-parameterize method
(same type of parameter but different behavior depending
on parameter)
 Separate Query from Modifier
(split method with individual focus on functioning)
Pulling and pushing methods and
fields
 Pull up method
 Pull up field
 Push down method
 Push down field
Communication and High-Level
Refactoring
 Refining hierarchies
Extract superclass, Extract subclass, collapse hierarchy
 Communication refactoring
Code smell: message chain, middle man
 Larger scale refactoring
Convert procedural to OO
Code smell: large classes, god classes, dumb data
Conclusion
References
 http://refactoring.com
Thank you

More Related Content

PDF
Bade Smells in Code
PDF
Clean code
PPTX
Graph database
PPTX
Balicasag
PPT
Class Project BBA 29
PPT
Zopa BBA 29
PDF
Jake O\'Connors Public House, Excelsior, MN
PDF
Lola\'s Lakehouse
Bade Smells in Code
Clean code
Graph database
Balicasag
Class Project BBA 29
Zopa BBA 29
Jake O\'Connors Public House, Excelsior, MN
Lola\'s Lakehouse

Viewers also liked (11)

PPTX
Apo Island
PPTX
Cabilao Island
PPT
Panglao Island
PPT
Class Project
PPTX
Malapascua Island
PPTX
Introduction to-angular js
PPTX
Olango And Mactan
PPTX
Rails best practices
PPTX
Application lifecycle management
PPT
bsc class project
PPTX
Southern Leyte
Apo Island
Cabilao Island
Panglao Island
Class Project
Malapascua Island
Introduction to-angular js
Olango And Mactan
Rails best practices
Application lifecycle management
bsc class project
Southern Leyte
Ad

Similar to Speeding up web_application (20)

PPTX
Code smells
PDF
Refactoring PHP
PPT
Code Refactoring - 3.0
PDF
Refactoring: Improve the design of existing code
PPT
Refactoring Tips by Martin Fowler
PPT
Code Refactoring
PDF
Bad Smell In Codes 1
PPTX
31 days Refactoring
PPTX
Bad Smells in Code
PDF
Refactoring 2TheMax (con ReSharper)
PDF
Refactoring
PPTX
SAD10 - Refactoring
PPTX
Refactoring Chapter 6,7.pptx
ODP
Refactoring: Improving the design of existing code
PDF
Refactoring
PPTX
Ruby code smells
PPTX
Refactoring
PDF
Code refactoring workshop (in Javascript)
PPTX
Code Refactoring
PDF
The Art of Refactoring | Asmit Ghimire | Gurzu.pdf
Code smells
Refactoring PHP
Code Refactoring - 3.0
Refactoring: Improve the design of existing code
Refactoring Tips by Martin Fowler
Code Refactoring
Bad Smell In Codes 1
31 days Refactoring
Bad Smells in Code
Refactoring 2TheMax (con ReSharper)
Refactoring
SAD10 - Refactoring
Refactoring Chapter 6,7.pptx
Refactoring: Improving the design of existing code
Refactoring
Ruby code smells
Refactoring
Code refactoring workshop (in Javascript)
Code Refactoring
The Art of Refactoring | Asmit Ghimire | Gurzu.pdf
Ad

Recently uploaded (20)

PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
August Patch Tuesday
PPTX
1. Introduction to Computer Programming.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Approach and Philosophy of On baking technology
PPTX
Programs and apps: productivity, graphics, security and other tools
PPT
Teaching material agriculture food technology
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
TLE Review Electricity (Electricity).pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Tartificialntelligence_presentation.pptx
PDF
Getting Started with Data Integration: FME Form 101
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
Unlocking AI with Model Context Protocol (MCP)
Mobile App Security Testing_ A Comprehensive Guide.pdf
August Patch Tuesday
1. Introduction to Computer Programming.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Approach and Philosophy of On baking technology
Programs and apps: productivity, graphics, security and other tools
Teaching material agriculture food technology
Digital-Transformation-Roadmap-for-Companies.pptx
Spectroscopy.pptx food analysis technology
gpt5_lecture_notes_comprehensive_20250812015547.pdf
TLE Review Electricity (Electricity).pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Heart disease approach using modified random forest and particle swarm optimi...
Encapsulation_ Review paper, used for researhc scholars
Tartificialntelligence_presentation.pptx
Getting Started with Data Integration: FME Form 101
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Group 1 Presentation -Planning and Decision Making .pptx

Speeding up web_application

  • 2. Refactoring Code  Making code better, may not be faster  Better structured, better built  More readable, more understandable  Easy to work with  Easy to add new features  Easy to spot and fix bugs  Keeping code in control  Improving existing code
  • 3. Contents  Introduction to Refactoring  Method-Level Refactoring  Class and Condition Focused Refactoring  Data Focused Refactoring  Communication and High Level Refactoring  Conclusion
  • 4. What ‘REFACTORING’ is?  Techniques of improving code that already exists  No rules that anyone can blindly follow to improve code  Techniques of recognize issues as per consciousness  Applied without thinking will be dangerous
  • 5. What ‘REFACTORING’ is NOT?  Not debugging  Not adding feature  Not changing observable behavior of code  Not performance improving
  • 7. When to use?  Write – Scan – Refactor at the end : INCORRECT  Write – Scan – Refactor regularly : CORRECT  Code reviews How to use?
  • 8. Code smell  Duplicated code  Long methods  Comments  Doesn’t tell what to do but tells us what to notice
  • 9. Method Level Refactoring  Preparing to refactor  Grouping refactorings together  Using the Extract Method refactoring  Extract Method with parameters and variables  Common code smells for Extract Method  Using IDEs for the Extract Method refactoring  The Inline Method refactoring  Refactorings that remove temps  Refactorings that add temps
  • 10. Preparing to refactor  Requirement of automated testing vs manual testing
  • 11. Grouping refactorings together  Individual Method(name? parameters? Temp variables? Duplicate? Too much in method?)  Context of method in class (right class? similarity with other methods class)  Communication between classes(inheritance)
  • 12. Extract Method refactoring  Smaller and specific is better  Provides reusability  Ease of overriding while using inheritance
  • 13. Extract Method with parameters  Parameters should be related to the method Extract Method with variables  Temporary variables can be extracted
  • 14. Code smells for using Extract Method  Long method  Comments(having comments vs need comments)
  • 15. Inline Method refactoring  Removing method that adds no value
  • 16. Refactoring to remove temps  Increase temptation to write longer methods  Change temps to small methods
  • 17. Refactoring to add temps  Split temporary variables  Introduce explaining variables  Remove assignments to parameters
  • 18. Split temporary variables  Don’t use same temporary variable for different purposes
  • 19. Introduce explaining variables  To improve readability  Introduce when a small method may not be required
  • 20. Remove assignments to parameters  Add temporary variables that assigns value to parameters may give undesired results
  • 21. Class and Condition Focused Refactoring  Move Method  Extract Class and Inline Class  Making conditions easier to read  Replacing conditions with polymorphism  Replacing type code with subclasses
  • 22. Move Method  Move method from one class to another  When a method interact with multiple classes then move it to the class with which it interacts more  Code smell: feature envy, inappropriate intimacy, shotgun surgery
  • 23. Extract Class and Inline Class  Code smell: Large class
  • 24. Making conditions easier to read  Decompose conditionals  Consolidate conditionals  Consolidate duplicate conditionals
  • 25. Replacing conditions with polymorphism  Conditions to check custom behavior
  • 26. Replacing type code with subclasses  Data can be categorized into subclasses
  • 27. Data Focused Refactoring  Moving and encapsulating fields  Working with data clumps  Simplifying method calls and parameter use  Pulling and pushing methods and fields
  • 28. Moving and encapsulating fields  If a field is more related and being used by the other class
  • 29. Working with data clumps  Preserve whole object (instead of parameters pass object)  Introduce parameter object (minimize parameters list by creating a class for set of parameters)
  • 30. Simplifying method calls and parameter use  Rename method  Remove parameter  Add parameter  Parameterize method (same behavior multiple methods)  De-parameterize method (same type of parameter but different behavior depending on parameter)  Separate Query from Modifier (split method with individual focus on functioning)
  • 31. Pulling and pushing methods and fields  Pull up method  Pull up field  Push down method  Push down field
  • 32. Communication and High-Level Refactoring  Refining hierarchies Extract superclass, Extract subclass, collapse hierarchy  Communication refactoring Code smell: message chain, middle man  Larger scale refactoring Convert procedural to OO Code smell: large classes, god classes, dumb data