SlideShare a Scribd company logo
Refactoring
FROM: HAFIZ AMMAR SIDDIQUI – COURSE: OBJECT ORIENTED SOFTWARE ENGINEERING – INSTITUTE: BEACONHOUSE NATIONAL UNIVERSITY
Refactoring
■ Process of changing a software system in such a way that it does not change its
external behavior but improves its internal structure
■ Restructure a software without changing its observable behavior
■ Improving the code of a software without adding new functionality or changing any
existing functionality
■ Process of cleaning up the code of a software without changing its output
– Enhances the readability of code
– Reduces the complexity in code
– Improves the maintainabilityof code
– Provides the extensibility for code
FROM: HAFIZ AMMAR SIDDIQUI – COURSE: OBJECT ORIENTED SOFTWARE ENGINEERING – INSTITUTE: BEACONHOUSE NATIONAL UNIVERSITY
Principles in Refactoring
FROM: HAFIZ AMMAR SIDDIQUI – COURSE: OBJECT ORIENTED SOFTWARE ENGINEERING – INSTITUTE: BEACONHOUSE NATIONAL UNIVERSITY
Principles in Refactoring
■ Why refactor?
– Improves the design of software
– Makes software easier to understand
– Helps in finding bugs
– Helps in programming faster
■ When to refactor?
– On adding a functionality
– On fixing an error
– On reviewing code
■ When not to refactor?
– If rewriting code from scratch
– If too much time is required
FROM: HAFIZ AMMAR SIDDIQUI – COURSE: OBJECT ORIENTED SOFTWARE ENGINEERING – INSTITUTE: BEACONHOUSE NATIONAL UNIVERSITY
Identifying Bad Smells
FROM: HAFIZ AMMAR SIDDIQUI – COURSE: OBJECT ORIENTED SOFTWARE ENGINEERING – INSTITUTE: BEACONHOUSE NATIONAL UNIVERSITY
Identifying Bad Smells
■ Duplicated code
– Extract method: If same code in multiple methods of same class
– Extract class: If same code in multiple classes
– Substitute algorithm: If same functionality at multiple places with different algorithm
■ Long method
– Extract method: If a part of a method can be separated
■ Large class
– Extract class: If a part of a class can be separated
– Extract subclass: If a part of a class can be extended into another class
■ Long parameter list
– Replace Parameter with Method: If parameters value can be obtained by a method
– Extract Parameter Object: If parameters can be grouped into an object
FROM: HAFIZ AMMAR SIDDIQUI – COURSE: OBJECT ORIENTED SOFTWARE ENGINEERING – INSTITUTE: BEACONHOUSE NATIONAL UNIVERSITY
Identifying Bad Smells
■ Temporary field
– Extract class: If all temporary fields can be put together separately
■ Data class
– Encapsulate Field: If class have public fields
– Remove Setting Method: If a field is read-only
■ Refused Bequest
– Push down method, Push down field: If a sibling class can be created to hold unused
■ Comments
– Extract method: If a block of code need a comment to explain what it does
– Rename method: If a method need a comment to explain what it does
FROM: HAFIZ AMMAR SIDDIQUI – COURSE: OBJECT ORIENTED SOFTWARE ENGINEERING – INSTITUTE: BEACONHOUSE NATIONAL UNIVERSITY
Reference
■ Refactoring: Improving the Design of Existing Code by Martin Fowler, Addison-
Wesley, 1999
FROM: HAFIZ AMMAR SIDDIQUI – COURSE: OBJECT ORIENTED SOFTWARE ENGINEERING – INSTITUTE: BEACONHOUSE NATIONAL UNIVERSITY

More Related Content

PDF
3-Software Anti Design Patterns (Object Oriented Software Engineering - BNU S...
PDF
5-Object Oriented Analysis (Object Oriented Software Engineering - BNU Spring...
PDF
6-Software Design Reviews (Object Oriented Software Engineering - BNU Spring ...
PDF
1-Introduction to Software Engineering (Object Oriented Software Engineering ...
PDF
2-Software Design (Object Oriented Software Engineering - BNU Spring 2017)
PDF
9-Software Verification and Validation (Object Oriented Software Engineering ...
PDF
Software Engineering : Process Models
PDF
Software Engineering : Software testing
3-Software Anti Design Patterns (Object Oriented Software Engineering - BNU S...
5-Object Oriented Analysis (Object Oriented Software Engineering - BNU Spring...
6-Software Design Reviews (Object Oriented Software Engineering - BNU Spring ...
1-Introduction to Software Engineering (Object Oriented Software Engineering ...
2-Software Design (Object Oriented Software Engineering - BNU Spring 2017)
9-Software Verification and Validation (Object Oriented Software Engineering ...
Software Engineering : Process Models
Software Engineering : Software testing

What's hot (14)

PDF
UML-test Application for Automated Validation of Students’ UML Class Diagram
PPTX
Unit 1 OOSE
PPTX
Software Cost Estimation Techniques
PPSX
Software engineering
PPTX
Software engineering
PPTX
Exam evaluation sytem
PPTX
Spiral Model
PPSX
COCOMO Model For Effort Estimation
PDF
1 modeling concepts
PDF
Osama Mohamed Saleh V1
PPT
Il product development - 20 01 2011
PPTX
01 software development life cycle
PPTX
software project management Cocomo model
PPTX
03 analysis of_requirementsspecification
UML-test Application for Automated Validation of Students’ UML Class Diagram
Unit 1 OOSE
Software Cost Estimation Techniques
Software engineering
Software engineering
Exam evaluation sytem
Spiral Model
COCOMO Model For Effort Estimation
1 modeling concepts
Osama Mohamed Saleh V1
Il product development - 20 01 2011
01 software development life cycle
software project management Cocomo model
03 analysis of_requirementsspecification
Ad

Similar to 7-Refactoring (Object Oriented Software Engineering - BNU Spring 2017) (20)

PDF
Refactoring: Improve the design of existing code
PPT
Code Refactoring
PPTX
Code smells
ODP
Refactoring: Improving the design of existing code
PDF
Refactoring PHP
PPTX
Code Refactoring
PDF
Refactoring, Therapeutic Attitude to Programming.
PPT
Code Refactoring - 3.0
PPT
Refactoring - improving the smell of your code
PDF
Bade Smells in Code
PPTX
refactoring code by clean code rules
PPTX
Refactoring
PDF
Refactoring
PDF
Bad Code Smells
PPT
Refactoring Tips by Martin Fowler
PPTX
Tech talks#6: Code Refactoring
PPTX
Clean Code
PPTX
Bad Smells in Code
PPTX
Refactoring
PPT
Writing Good Code
Refactoring: Improve the design of existing code
Code Refactoring
Code smells
Refactoring: Improving the design of existing code
Refactoring PHP
Code Refactoring
Refactoring, Therapeutic Attitude to Programming.
Code Refactoring - 3.0
Refactoring - improving the smell of your code
Bade Smells in Code
refactoring code by clean code rules
Refactoring
Refactoring
Bad Code Smells
Refactoring Tips by Martin Fowler
Tech talks#6: Code Refactoring
Clean Code
Bad Smells in Code
Refactoring
Writing Good Code
Ad

More from Hafiz Ammar Siddiqui (10)

PDF
4-Game Physics (Game Design and Development)
PDF
3-Game Graphics (Game Design and Development)
PDF
2-Game Design (Game Design and Development)
PDF
1-Introduction (Game Design and Development)
PDF
10-Software Project Management (Object Oriented Software Engineering - BNU Sp...
PDF
9-Game Design (Game Development - UMT Spring 2017/2018)
PDF
4-Object Oriented Design Heuristics (Object Oriented Software Engineering - B...
PDF
6-Animation in Game (Game Development - UMT Spring 2017/2018)
PDF
3-Graphics in Game (Game Development - UMT Spring 2017/2018)
PDF
1-Introduction (Game Development - UMT Spring 2017/2018)
4-Game Physics (Game Design and Development)
3-Game Graphics (Game Design and Development)
2-Game Design (Game Design and Development)
1-Introduction (Game Design and Development)
10-Software Project Management (Object Oriented Software Engineering - BNU Sp...
9-Game Design (Game Development - UMT Spring 2017/2018)
4-Object Oriented Design Heuristics (Object Oriented Software Engineering - B...
6-Animation in Game (Game Development - UMT Spring 2017/2018)
3-Graphics in Game (Game Development - UMT Spring 2017/2018)
1-Introduction (Game Development - UMT Spring 2017/2018)

Recently uploaded (20)

PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Classroom Observation Tools for Teachers
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Lesson notes of climatology university.
PDF
01-Introduction-to-Information-Management.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Cell Types and Its function , kingdom of life
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Institutional Correction lecture only . . .
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Final Presentation General Medicine 03-08-2024.pptx
Classroom Observation Tools for Teachers
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPH.pptx obstetrics and gynecology in nursing
VCE English Exam - Section C Student Revision Booklet
Lesson notes of climatology university.
01-Introduction-to-Information-Management.pdf
Basic Mud Logging Guide for educational purpose
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
human mycosis Human fungal infections are called human mycosis..pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
TR - Agricultural Crops Production NC III.pdf
Cell Types and Its function , kingdom of life
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Institutional Correction lecture only . . .
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
3rd Neelam Sanjeevareddy Memorial Lecture.pdf

7-Refactoring (Object Oriented Software Engineering - BNU Spring 2017)

  • 1. Refactoring FROM: HAFIZ AMMAR SIDDIQUI – COURSE: OBJECT ORIENTED SOFTWARE ENGINEERING – INSTITUTE: BEACONHOUSE NATIONAL UNIVERSITY
  • 2. Refactoring ■ Process of changing a software system in such a way that it does not change its external behavior but improves its internal structure ■ Restructure a software without changing its observable behavior ■ Improving the code of a software without adding new functionality or changing any existing functionality ■ Process of cleaning up the code of a software without changing its output – Enhances the readability of code – Reduces the complexity in code – Improves the maintainabilityof code – Provides the extensibility for code FROM: HAFIZ AMMAR SIDDIQUI – COURSE: OBJECT ORIENTED SOFTWARE ENGINEERING – INSTITUTE: BEACONHOUSE NATIONAL UNIVERSITY
  • 3. Principles in Refactoring FROM: HAFIZ AMMAR SIDDIQUI – COURSE: OBJECT ORIENTED SOFTWARE ENGINEERING – INSTITUTE: BEACONHOUSE NATIONAL UNIVERSITY
  • 4. Principles in Refactoring ■ Why refactor? – Improves the design of software – Makes software easier to understand – Helps in finding bugs – Helps in programming faster ■ When to refactor? – On adding a functionality – On fixing an error – On reviewing code ■ When not to refactor? – If rewriting code from scratch – If too much time is required FROM: HAFIZ AMMAR SIDDIQUI – COURSE: OBJECT ORIENTED SOFTWARE ENGINEERING – INSTITUTE: BEACONHOUSE NATIONAL UNIVERSITY
  • 5. Identifying Bad Smells FROM: HAFIZ AMMAR SIDDIQUI – COURSE: OBJECT ORIENTED SOFTWARE ENGINEERING – INSTITUTE: BEACONHOUSE NATIONAL UNIVERSITY
  • 6. Identifying Bad Smells ■ Duplicated code – Extract method: If same code in multiple methods of same class – Extract class: If same code in multiple classes – Substitute algorithm: If same functionality at multiple places with different algorithm ■ Long method – Extract method: If a part of a method can be separated ■ Large class – Extract class: If a part of a class can be separated – Extract subclass: If a part of a class can be extended into another class ■ Long parameter list – Replace Parameter with Method: If parameters value can be obtained by a method – Extract Parameter Object: If parameters can be grouped into an object FROM: HAFIZ AMMAR SIDDIQUI – COURSE: OBJECT ORIENTED SOFTWARE ENGINEERING – INSTITUTE: BEACONHOUSE NATIONAL UNIVERSITY
  • 7. Identifying Bad Smells ■ Temporary field – Extract class: If all temporary fields can be put together separately ■ Data class – Encapsulate Field: If class have public fields – Remove Setting Method: If a field is read-only ■ Refused Bequest – Push down method, Push down field: If a sibling class can be created to hold unused ■ Comments – Extract method: If a block of code need a comment to explain what it does – Rename method: If a method need a comment to explain what it does FROM: HAFIZ AMMAR SIDDIQUI – COURSE: OBJECT ORIENTED SOFTWARE ENGINEERING – INSTITUTE: BEACONHOUSE NATIONAL UNIVERSITY
  • 8. Reference ■ Refactoring: Improving the Design of Existing Code by Martin Fowler, Addison- Wesley, 1999 FROM: HAFIZ AMMAR SIDDIQUI – COURSE: OBJECT ORIENTED SOFTWARE ENGINEERING – INSTITUTE: BEACONHOUSE NATIONAL UNIVERSITY