SlideShare a Scribd company logo
What is Refactoring
Refactoring is the process of changing a software system in
such a way that it does not alter the external behavior of the
code yet improves its internal structure.
Why refactor?
● When you need to either fix a bug or add a new feature,
then implementing the code necessary would be a lot
easier once you had refactored it to be in a more stable,
and understandable state.
● The most suitable time to start refactoring is when you are
fixing bugs or adding a new feature, and it should be done
during the life cycle of the project not at the end.
Testing while Refactoring
● Its important to perform regular tests during refactoring to
make sure that you do not break anything during
refactoring as refactoring main concern is not to change
the API.
Techniques
1-Rename methods:
Giving methods/attributes names that reduce the need of the
comments and help to promote greater clarity.
2-Introduce explaining variables:
Expressions can become very complex and hard to read. In such
situations temporary variables can be helpful to break down the
expression into something more manageable.
Example:
if ((platform.upcase().index("MAC") > -1) should become
– isMacOs = platform.upcase().index("MAC") > -1
– if (isMacOs)
Techniques
3-Inline Temp:
temp variables that makes method longer and they only used once and
they are simple expressions.
– Inline Temp effectively removes the temp variable altogether by just
using the value assigned to it.
– Example:
– temp_variable_with_descriptive_name = add_stuff
puts "Number is #{temp_variable_with_descriptive_name}"
– Becomes "Number is #add_stuff}"
Techniques
4-Split Temp Variable:
– if a temporary variable is assigned to more than once and it is not a loop
variable or a collecting/accumulator variable then it is a temp considered to
have too many responsibilities.
– Example:
– Temp = a+b
– Temp = a-b should become
– Sum = a + b
– Diff = a - b
5-Replace Temp With Query:
You are using a temporary variable to hold the result of an expression.
– Complex expression assigned to the temp needs to be first moved to a
method.
–
Techniques
Example:
def volume
# `area` is the temp
area = length * width
area * height
end
Should become
def volume
# notice `area` is now a direct method call
area * height
end
def area
length * width
end
●
●
Techniques
6-Replace Temp With Chain:
f you have a temp variable holding the result of calling an object's method, and
follow the assignment by using that temp to carry out more method calls, then you
should consider chaining method calls instead by making sure that every function
returns self of the object.
– Example:
– temp = College.new
– temp.create_course
– temp.add_student
– Should become
– college = College.create_course
– .add_student
Techniques
7-Extract Method:
It consists of breaking up long methods by shifting overly complex chunks of
code into new methods which have very descriptive identifiers.
– Example:
– Def printOwing
– printBanner
–
– //print details
– Puts "name: " + _name
– Puts "amount " + getOutstanding
– end
Should become
– Def printOwing
– printBanner
– printDetails(getOutstanding())
– end
–
– def printDetails ( outstanding)
– Puts "name: " + _name
– Puts "amount " + outstanding
– end
–
Techniques
8-Inline Method:
if method is not used more than once and perform a very simple line of code so we
will do the exact opposite of extract method.
9-Move Method:
If a method is asking another class a lot of questions then it may be an
indication the method is on the wrong object.
– So we should move the method to the other class and change the
required differences in the methhods
10-Replace Method With Method Object:
you have a long method you want to use Extract Method on, but the number of
temporary local variables are too great to allow you to utilise the Extract Method
technique (because passing around that many variables would be just as messy as
the long method itself.
Techniques
11-Replace Loop With Collection Closure Method:
you hide the ugly details of the loop behind a nicer iteration method, allowing the
developer looking at the code to focus on the business logic instead.
– Example:
– managers = []
– employees.each do |e|
– managers << e if e.manager?
– End
– Should becomes
– managers = employees.select { |e| e.manager? }
12-Pull Up Method:
When you have duplicated code across two separate classes then the best
refactoring technique to implement is to pull that duplicate code up into a super class.
(oop concpet)
Techniques
13-Form Template Method:
You have two methods in subclasses that perform similar steps in the
same order, yet the steps are different.
– Get the steps into methods with the same signature, so that the original
methods become the same. Then you can pull them up.(OOP Concept)
14-Extract Surrounding Method:
If you find you have different methods which contain almost identical
code but with a slight variant in the middle, then pull up the duplicated
code into a single method and pass a code block to the newly created
method.
Techniques
15-Self Encapsulate Field:
When inheriting properties from a parent class/object then it can be more
flexible if the parent class only allows access to the properties from
within a getter/setter.(OOP Concept)
16-Introduce Named Parameter:
When method arguments are unclear then convert them into named
parameters so they become clearer.
– Example:
def turnOnTheTV (channel: 1, volume: 1); end
– turnOnTheTV(channel: 101, volume: 10)

More Related Content

What's hot

Bad Code Smells
Bad Code SmellsBad Code Smells
Bad Code Smells
kim.mens
 
extreme Programming
extreme Programmingextreme Programming
extreme Programming
Bilal Shah
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
Mario Sangiorgio
 
Software Engineering - chp4- design patterns
Software Engineering - chp4- design patternsSoftware Engineering - chp4- design patterns
Software Engineering - chp4- design patterns
Lilia Sfaxi
 
Clean pragmatic architecture @ devflix
Clean pragmatic architecture @ devflixClean pragmatic architecture @ devflix
Clean pragmatic architecture @ devflix
Victor Rentea
 
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
 
Clean code
Clean codeClean code
Clean code
ifnu bima
 
Code Refactoring
Code RefactoringCode Refactoring
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
Asma CHERIF
 
Adapter pattern
Adapter patternAdapter pattern
Adapter pattern
Shakil Ahmed
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
Hawkman Academy
 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English version
saber tabatabaee
 
The Extreme Programming (XP) Model
The Extreme Programming (XP) ModelThe Extreme Programming (XP) Model
The Extreme Programming (XP) Model
Damian T. Gordon
 
Code refactoring
Code refactoringCode refactoring
Code refactoring
Lalit Kale
 
Clean architecture - Protecting the Domain
Clean architecture - Protecting the DomainClean architecture - Protecting the Domain
Clean architecture - Protecting the Domain
Victor Rentea
 
Refactoring: Improve the design of existing code
Refactoring: Improve the design of existing codeRefactoring: Improve the design of existing code
Refactoring: Improve the design of existing code
Valerio Maggio
 
Software Architecture and Design
Software Architecture and DesignSoftware Architecture and Design
Software Architecture and Design
Ra'Fat Al-Msie'deen
 
SE2018_Lec 18_ Design Principles and Design Patterns
SE2018_Lec 18_ Design Principles and Design PatternsSE2018_Lec 18_ Design Principles and Design Patterns
SE2018_Lec 18_ Design Principles and Design Patterns
Amr E. Mohamed
 

What's hot (20)

Bad Code Smells
Bad Code SmellsBad Code Smells
Bad Code Smells
 
extreme Programming
extreme Programmingextreme Programming
extreme Programming
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
 
Software Engineering - chp4- design patterns
Software Engineering - chp4- design patternsSoftware Engineering - chp4- design patterns
Software Engineering - chp4- design patterns
 
Clean pragmatic architecture @ devflix
Clean pragmatic architecture @ devflixClean pragmatic architecture @ devflix
Clean pragmatic architecture @ devflix
 
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)
 
Clean code
Clean codeClean code
Clean code
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoring
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
 
Adapter pattern
Adapter patternAdapter pattern
Adapter pattern
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English version
 
The Extreme Programming (XP) Model
The Extreme Programming (XP) ModelThe Extreme Programming (XP) Model
The Extreme Programming (XP) Model
 
Feature Driven Development
Feature Driven DevelopmentFeature Driven Development
Feature Driven Development
 
Code refactoring
Code refactoringCode refactoring
Code refactoring
 
Incremental model
Incremental modelIncremental model
Incremental model
 
Clean architecture - Protecting the Domain
Clean architecture - Protecting the DomainClean architecture - Protecting the Domain
Clean architecture - Protecting the Domain
 
Refactoring: Improve the design of existing code
Refactoring: Improve the design of existing codeRefactoring: Improve the design of existing code
Refactoring: Improve the design of existing code
 
Software Architecture and Design
Software Architecture and DesignSoftware Architecture and Design
Software Architecture and Design
 
SE2018_Lec 18_ Design Principles and Design Patterns
SE2018_Lec 18_ Design Principles and Design PatternsSE2018_Lec 18_ Design Principles and Design Patterns
SE2018_Lec 18_ Design Principles and Design Patterns
 

Viewers also liked

The Value of Refactoring on an Agile Team
The Value of Refactoring on an Agile TeamThe Value of Refactoring on an Agile Team
The Value of Refactoring on an Agile Team
Rob Myers
 
Riding the Agile Wave
Riding the Agile WaveRiding the Agile Wave
Riding the Agile Wave
NUS-ISS
 
Introduction to Refactoring
Introduction to RefactoringIntroduction to Refactoring
Introduction to Refactoring
Niels Verdonk
 
Agile Development Ultimate Slides
Agile Development Ultimate SlidesAgile Development Ultimate Slides
Agile Development Ultimate Slidesgilashikwa
 
Estimating and planning Agile projects
Estimating and planning Agile projectsEstimating and planning Agile projects
Estimating and planning Agile projects
Murray Robinson
 
Release Management: Successful Software Releases Start with a Plan
Release Management: Successful Software Releases Start with a PlanRelease Management: Successful Software Releases Start with a Plan
Release Management: Successful Software Releases Start with a Plan
connielharper
 
Agile Release Planning
Agile Release PlanningAgile Release Planning
Agile Release Planning
Adnan Aziz
 

Viewers also liked (7)

The Value of Refactoring on an Agile Team
The Value of Refactoring on an Agile TeamThe Value of Refactoring on an Agile Team
The Value of Refactoring on an Agile Team
 
Riding the Agile Wave
Riding the Agile WaveRiding the Agile Wave
Riding the Agile Wave
 
Introduction to Refactoring
Introduction to RefactoringIntroduction to Refactoring
Introduction to Refactoring
 
Agile Development Ultimate Slides
Agile Development Ultimate SlidesAgile Development Ultimate Slides
Agile Development Ultimate Slides
 
Estimating and planning Agile projects
Estimating and planning Agile projectsEstimating and planning Agile projects
Estimating and planning Agile projects
 
Release Management: Successful Software Releases Start with a Plan
Release Management: Successful Software Releases Start with a PlanRelease Management: Successful Software Releases Start with a Plan
Release Management: Successful Software Releases Start with a Plan
 
Agile Release Planning
Agile Release PlanningAgile Release Planning
Agile Release Planning
 

Similar to Refactoring Techniques

Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler design
Anul Chaudhary
 
Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual
Abdul Hannan
 
Agile korea 2013 유석문
Agile korea 2013 유석문Agile korea 2013 유석문
Agile korea 2013 유석문Sangcheol Hwang
 
Refactoring Chapter 6,7.pptx
Refactoring Chapter 6,7.pptxRefactoring Chapter 6,7.pptx
Refactoring Chapter 6,7.pptx
Eskişehir Technical University
 
31 days Refactoring
31 days Refactoring31 days Refactoring
31 days Refactoring
Ahasanul Kalam Akib
 
cs2 report (rommel platilla mabini colleges) back-up
cs2 report (rommel platilla mabini colleges) back-upcs2 report (rommel platilla mabini colleges) back-up
cs2 report (rommel platilla mabini colleges) back-up
guestd607e747
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
DeepikaV81
 
Refactoring: Improving the design of existing code. Chapter 6.
Refactoring: Improving the design of existing code. Chapter 6.Refactoring: Improving the design of existing code. Chapter 6.
Refactoring: Improving the design of existing code. Chapter 6.
Andrés Callejas González
 
Mca2030 object oriented programming – c++
Mca2030  object oriented programming – c++Mca2030  object oriented programming – c++
Mca2030 object oriented programming – c++
smumbahelp
 
Peephole optimization techniques
Peephole optimization techniquesPeephole optimization techniques
Peephole optimization techniques
garishma bhatia
 
Unit 3 part2
Unit 3 part2Unit 3 part2
Unit 3 part2
Karthik Vivek
 
Unit 3 part2
Unit 3 part2Unit 3 part2
Unit 3 part2
Karthik Vivek
 
Unit 3 part2
Unit 3 part2Unit 3 part2
Unit 3 part2
Karthik Vivek
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
imedo.de
 
Soild principles
Soild principlesSoild principles
Soild principles
Avidnyat Chiddarwar
 
Refactoring PHP
Refactoring PHPRefactoring PHP
Refactoring PHP
Adam Culp
 
Refactoring
RefactoringRefactoring
Refactoring
AngelLuisBlasco
 
Implementation
ImplementationImplementation
Implementation
adil raja
 
Need to make a horizontal change across 100+ microservices? No worries, Sheph...
Need to make a horizontal change across 100+ microservices? No worries, Sheph...Need to make a horizontal change across 100+ microservices? No worries, Sheph...
Need to make a horizontal change across 100+ microservices? No worries, Sheph...
Aori Nevo, PhD
 
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
DevDay.org
 

Similar to Refactoring Techniques (20)

Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler design
 
Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual
 
Agile korea 2013 유석문
Agile korea 2013 유석문Agile korea 2013 유석문
Agile korea 2013 유석문
 
Refactoring Chapter 6,7.pptx
Refactoring Chapter 6,7.pptxRefactoring Chapter 6,7.pptx
Refactoring Chapter 6,7.pptx
 
31 days Refactoring
31 days Refactoring31 days Refactoring
31 days Refactoring
 
cs2 report (rommel platilla mabini colleges) back-up
cs2 report (rommel platilla mabini colleges) back-upcs2 report (rommel platilla mabini colleges) back-up
cs2 report (rommel platilla mabini colleges) back-up
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
 
Refactoring: Improving the design of existing code. Chapter 6.
Refactoring: Improving the design of existing code. Chapter 6.Refactoring: Improving the design of existing code. Chapter 6.
Refactoring: Improving the design of existing code. Chapter 6.
 
Mca2030 object oriented programming – c++
Mca2030  object oriented programming – c++Mca2030  object oriented programming – c++
Mca2030 object oriented programming – c++
 
Peephole optimization techniques
Peephole optimization techniquesPeephole optimization techniques
Peephole optimization techniques
 
Unit 3 part2
Unit 3 part2Unit 3 part2
Unit 3 part2
 
Unit 3 part2
Unit 3 part2Unit 3 part2
Unit 3 part2
 
Unit 3 part2
Unit 3 part2Unit 3 part2
Unit 3 part2
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Soild principles
Soild principlesSoild principles
Soild principles
 
Refactoring PHP
Refactoring PHPRefactoring PHP
Refactoring PHP
 
Refactoring
RefactoringRefactoring
Refactoring
 
Implementation
ImplementationImplementation
Implementation
 
Need to make a horizontal change across 100+ microservices? No worries, Sheph...
Need to make a horizontal change across 100+ microservices? No worries, Sheph...Need to make a horizontal change across 100+ microservices? No worries, Sheph...
Need to make a horizontal change across 100+ microservices? No worries, Sheph...
 
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
 

Recently uploaded

Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 

Recently uploaded (20)

Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 

Refactoring Techniques

  • 1. What is Refactoring Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code yet improves its internal structure.
  • 2. Why refactor? ● When you need to either fix a bug or add a new feature, then implementing the code necessary would be a lot easier once you had refactored it to be in a more stable, and understandable state. ● The most suitable time to start refactoring is when you are fixing bugs or adding a new feature, and it should be done during the life cycle of the project not at the end.
  • 3. Testing while Refactoring ● Its important to perform regular tests during refactoring to make sure that you do not break anything during refactoring as refactoring main concern is not to change the API.
  • 4. Techniques 1-Rename methods: Giving methods/attributes names that reduce the need of the comments and help to promote greater clarity. 2-Introduce explaining variables: Expressions can become very complex and hard to read. In such situations temporary variables can be helpful to break down the expression into something more manageable. Example: if ((platform.upcase().index("MAC") > -1) should become – isMacOs = platform.upcase().index("MAC") > -1 – if (isMacOs)
  • 5. Techniques 3-Inline Temp: temp variables that makes method longer and they only used once and they are simple expressions. – Inline Temp effectively removes the temp variable altogether by just using the value assigned to it. – Example: – temp_variable_with_descriptive_name = add_stuff puts "Number is #{temp_variable_with_descriptive_name}" – Becomes "Number is #add_stuff}"
  • 6. Techniques 4-Split Temp Variable: – if a temporary variable is assigned to more than once and it is not a loop variable or a collecting/accumulator variable then it is a temp considered to have too many responsibilities. – Example: – Temp = a+b – Temp = a-b should become – Sum = a + b – Diff = a - b 5-Replace Temp With Query: You are using a temporary variable to hold the result of an expression. – Complex expression assigned to the temp needs to be first moved to a method. –
  • 7. Techniques Example: def volume # `area` is the temp area = length * width area * height end Should become def volume # notice `area` is now a direct method call area * height end def area length * width end ● ●
  • 8. Techniques 6-Replace Temp With Chain: f you have a temp variable holding the result of calling an object's method, and follow the assignment by using that temp to carry out more method calls, then you should consider chaining method calls instead by making sure that every function returns self of the object. – Example: – temp = College.new – temp.create_course – temp.add_student – Should become – college = College.create_course – .add_student
  • 9. Techniques 7-Extract Method: It consists of breaking up long methods by shifting overly complex chunks of code into new methods which have very descriptive identifiers. – Example: – Def printOwing – printBanner – – //print details – Puts "name: " + _name – Puts "amount " + getOutstanding – end Should become – Def printOwing – printBanner – printDetails(getOutstanding()) – end – – def printDetails ( outstanding) – Puts "name: " + _name – Puts "amount " + outstanding – end –
  • 10. Techniques 8-Inline Method: if method is not used more than once and perform a very simple line of code so we will do the exact opposite of extract method. 9-Move Method: If a method is asking another class a lot of questions then it may be an indication the method is on the wrong object. – So we should move the method to the other class and change the required differences in the methhods 10-Replace Method With Method Object: you have a long method you want to use Extract Method on, but the number of temporary local variables are too great to allow you to utilise the Extract Method technique (because passing around that many variables would be just as messy as the long method itself.
  • 11. Techniques 11-Replace Loop With Collection Closure Method: you hide the ugly details of the loop behind a nicer iteration method, allowing the developer looking at the code to focus on the business logic instead. – Example: – managers = [] – employees.each do |e| – managers << e if e.manager? – End – Should becomes – managers = employees.select { |e| e.manager? } 12-Pull Up Method: When you have duplicated code across two separate classes then the best refactoring technique to implement is to pull that duplicate code up into a super class. (oop concpet)
  • 12. Techniques 13-Form Template Method: You have two methods in subclasses that perform similar steps in the same order, yet the steps are different. – Get the steps into methods with the same signature, so that the original methods become the same. Then you can pull them up.(OOP Concept) 14-Extract Surrounding Method: If you find you have different methods which contain almost identical code but with a slight variant in the middle, then pull up the duplicated code into a single method and pass a code block to the newly created method.
  • 13. Techniques 15-Self Encapsulate Field: When inheriting properties from a parent class/object then it can be more flexible if the parent class only allows access to the properties from within a getter/setter.(OOP Concept) 16-Introduce Named Parameter: When method arguments are unclear then convert them into named parameters so they become clearer. – Example: def turnOnTheTV (channel: 1, volume: 1); end – turnOnTheTV(channel: 101, volume: 10)