SlideShare a Scribd company logo
Refactoring
By Rabeya Bashri
Refactoring
What is Refactoring
Why should we use Refactoring
When should we use Refactoring
When should not we use Refactoring
Why Refactoring works
Problem with Refactoring
Some Scenario
Conclusion
What is Refactoring
 a disciplined technique, used for restructuring an existing body of code
 altering its internal structure without changing its external behavior
 Its heart is a series of small behavior preserving transformations. Each
transformation does little, but a sequence of transformations can produce a
significant restructuring.
 Refactoring (noun): a change made to the internal structure of software to
make it easier to understand and cheaper to modify without changing its
observable behavior.
 Refactor (verb): to restructure software by applying a series of refactorings
without changing its observable behavior.
 it provides a technique for cleaning up code in a more efficient and
controlled manner.
Why should we use Refactoring
 Refactoring Improves the Design of Software
 It becomes harder to see the design by reading the code.
 Regular refactoring helps code retain its shape.
 Poorly designed code usually takes more code to do the same things, often
because the code quite literally does the same thing in several places. Thus an
important aspect of improving design is to eliminate duplicate code.
 By eliminating the duplicates, you ensure that the code says everything once
and only once, which is the essence of good design.
 Refactoring Makes Software Easier to Understand
 It does matter if it takes a programmer a week to make a change that would
have taken only an hour if programmer had understood your code.
 Refactoring Helps You Find Bugs
 Refactoring helps programmer be much more effective at writing robust code.
 Refactoring Helps You Program Faster
 a good design is essential for rapid software development.
 Without a good design, you can progress quickly for a while, but soon the poor
design starts to slow you down. You spend time finding and fixing bugs instead
of adding new function. Changes take longer as you try to understand the
system and find the duplicate code.
When should we use Refactoring
 refactoring is not an activity you set aside time to do. Refactoring is
something you do all the time in little bursts. You don’t decide to
refactor, you refactor because you want to do something else, and
refactoring helps you do that other thing.
 The Rule of Three
 Refactor When You Add Function
 Refactor When You Need to Fix a Bug
 Refactor As You Do a Code Review
When should not we use Refactoring
 A clear sign of the need to rewrite is when the current code
just does not work. You may discover this only by trying to
test it and discovering that the code is so full of bugs that you
cannot stablilize it. Remember, code has to work mostly
correctly before you refactor.
 The other time you should avoid refactoring is when you are
close to a deadline. At that point the productivity gain from
refactoring would appear after the deadline and thus be too
late.
Why Refactoring works
 What is it that makes programs hard to work with? Four
things I can think of as I am typing this are as follows:
Programs that are hard to read are hard to modify.
Programs that have duplicated logic are hard
to modify.
Programs that require additional behavior that
requires you to change running code are hard
to modify.
Programs with complex conditional logic are hard
to modify.
 So, we want programs that are easy to read, that have
all logic specified in one and only one place, that do not
allow changes to endanger existing behavior, and that
allow conditional logic to be expressed as simply
as possible.
Problem with Refactoring
 Databases
 One problem area for refactoring is databases. Most business
applications are tightly coupled to the database schema that supports
them.That’s one reason that the database is difficult to change.
 Another reason is data migration. Even if you have carefully layered
your system to minimize the dependencies between the database
schema and the object model, changing the database schema forces
you to migrate the data, which can be a long and fraught task.
 Changing Interfaces
 Something that is disturbing about refactoring is that many of the
refactorings do change an interface.
 Design Changes That Are Difficult to Refactor
Considerable scenario for refactoring
 Duplicate Code
 Long Method
 Larger Class
 Long Parameter List
Conclusion
Refactoring is the process of taking a running program and
adding to its value, not by changing its behavior but by giving
it more of these qualities that enable us to continue
developing at speed.

More Related Content

PPT
Principles in Refactoring
PPTX
Plug in framework made easy
PDF
Functional Programmer's Starter Kit
PPT
Open ERP's Community Organisation
PPT
Five essential elements for successful software development
PDF
SharePoint Apps - SharePoint Day 2013
PDF
Importance of solution architecture
Principles in Refactoring
Plug in framework made easy
Functional Programmer's Starter Kit
Open ERP's Community Organisation
Five essential elements for successful software development
SharePoint Apps - SharePoint Day 2013
Importance of solution architecture

Similar to Refactoring (20)

PPT
Principlesinrefactoring 090906230021-phpapp01
PDF
Refactoring 2 The Max
PDF
Put to the Test
PDF
Software Development Standard Operating Procedure
PDF
The Power Of Refactoring (4developers Krakow)
PDF
Software design.edited (1)
PPTX
Test Drive Dirven Driver HAHAahhaha.pptx
PDF
Coding With JRebel - Java Forever Changed
PDF
Coding With JRebel - Java Forever Changed
PDF
Coding With JRebel - Java Forever Changed
PPT
Extreme programming
PDF
Devops Explained & Best Practices
PDF
Refactoring PHP
PDF
How can JAVA Performance tuning speed up applications.pdf
PDF
The Power Of Refactoring (php|tek 09)
PPTX
Top 10 React Development Tools to Choose in 2023.pptx
PDF
L5555555555555555555555 Agile Scrum Framework.pdf
PDF
Test driven development and react js application go hand in hand
PDF
Patterns And Practices For Infrastructure As Code With Examples In Python And...
PPTX
Agile Values, Principles and Practices
Principlesinrefactoring 090906230021-phpapp01
Refactoring 2 The Max
Put to the Test
Software Development Standard Operating Procedure
The Power Of Refactoring (4developers Krakow)
Software design.edited (1)
Test Drive Dirven Driver HAHAahhaha.pptx
Coding With JRebel - Java Forever Changed
Coding With JRebel - Java Forever Changed
Coding With JRebel - Java Forever Changed
Extreme programming
Devops Explained & Best Practices
Refactoring PHP
How can JAVA Performance tuning speed up applications.pdf
The Power Of Refactoring (php|tek 09)
Top 10 React Development Tools to Choose in 2023.pptx
L5555555555555555555555 Agile Scrum Framework.pdf
Test driven development and react js application go hand in hand
Patterns And Practices For Infrastructure As Code With Examples In Python And...
Agile Values, Principles and Practices
Ad

Recently uploaded (20)

PDF
Approach and Philosophy of On baking technology
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
KodekX | Application Modernization Development
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Encapsulation theory and applications.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Electronic commerce courselecture one. Pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
Approach and Philosophy of On baking technology
Per capita expenditure prediction using model stacking based on satellite ima...
NewMind AI Weekly Chronicles - August'25 Week I
“AI and Expert System Decision Support & Business Intelligence Systems”
KodekX | Application Modernization Development
Building Integrated photovoltaic BIPV_UPV.pdf
Encapsulation theory and applications.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Big Data Technologies - Introduction.pptx
Spectroscopy.pptx food analysis technology
Spectral efficient network and resource selection model in 5G networks
20250228 LYD VKU AI Blended-Learning.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Electronic commerce courselecture one. Pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Ad

Refactoring

  • 2. Refactoring What is Refactoring Why should we use Refactoring When should we use Refactoring When should not we use Refactoring Why Refactoring works Problem with Refactoring Some Scenario Conclusion
  • 3. What is Refactoring  a disciplined technique, used for restructuring an existing body of code  altering its internal structure without changing its external behavior  Its heart is a series of small behavior preserving transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring.  Refactoring (noun): a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior.  Refactor (verb): to restructure software by applying a series of refactorings without changing its observable behavior.  it provides a technique for cleaning up code in a more efficient and controlled manner.
  • 4. Why should we use Refactoring  Refactoring Improves the Design of Software  It becomes harder to see the design by reading the code.  Regular refactoring helps code retain its shape.  Poorly designed code usually takes more code to do the same things, often because the code quite literally does the same thing in several places. Thus an important aspect of improving design is to eliminate duplicate code.  By eliminating the duplicates, you ensure that the code says everything once and only once, which is the essence of good design.  Refactoring Makes Software Easier to Understand  It does matter if it takes a programmer a week to make a change that would have taken only an hour if programmer had understood your code.  Refactoring Helps You Find Bugs  Refactoring helps programmer be much more effective at writing robust code.  Refactoring Helps You Program Faster  a good design is essential for rapid software development.  Without a good design, you can progress quickly for a while, but soon the poor design starts to slow you down. You spend time finding and fixing bugs instead of adding new function. Changes take longer as you try to understand the system and find the duplicate code.
  • 5. When should we use Refactoring  refactoring is not an activity you set aside time to do. Refactoring is something you do all the time in little bursts. You don’t decide to refactor, you refactor because you want to do something else, and refactoring helps you do that other thing.  The Rule of Three  Refactor When You Add Function  Refactor When You Need to Fix a Bug  Refactor As You Do a Code Review
  • 6. When should not we use Refactoring  A clear sign of the need to rewrite is when the current code just does not work. You may discover this only by trying to test it and discovering that the code is so full of bugs that you cannot stablilize it. Remember, code has to work mostly correctly before you refactor.  The other time you should avoid refactoring is when you are close to a deadline. At that point the productivity gain from refactoring would appear after the deadline and thus be too late.
  • 7. Why Refactoring works  What is it that makes programs hard to work with? Four things I can think of as I am typing this are as follows: Programs that are hard to read are hard to modify. Programs that have duplicated logic are hard to modify. Programs that require additional behavior that requires you to change running code are hard to modify. Programs with complex conditional logic are hard to modify.  So, we want programs that are easy to read, that have all logic specified in one and only one place, that do not allow changes to endanger existing behavior, and that allow conditional logic to be expressed as simply as possible.
  • 8. Problem with Refactoring  Databases  One problem area for refactoring is databases. Most business applications are tightly coupled to the database schema that supports them.That’s one reason that the database is difficult to change.  Another reason is data migration. Even if you have carefully layered your system to minimize the dependencies between the database schema and the object model, changing the database schema forces you to migrate the data, which can be a long and fraught task.  Changing Interfaces  Something that is disturbing about refactoring is that many of the refactorings do change an interface.  Design Changes That Are Difficult to Refactor
  • 9. Considerable scenario for refactoring  Duplicate Code  Long Method  Larger Class  Long Parameter List
  • 10. Conclusion Refactoring is the process of taking a running program and adding to its value, not by changing its behavior but by giving it more of these qualities that enable us to continue developing at speed.