![Page 1: 7-Refactoring (Object Oriented Software Engineering - BNU Spring 2017)](https://reader037.vdocument.in/reader037/viewer/2022100803/5a65ab327f8b9ab3488b4b69/html5/thumbnails/1.jpg)
Refactoring
FROM: HAFIZ AMMAR SIDDIQUI – COURSE: OBJECT ORIENTED SOFTWARE ENGINEERING – INSTITUTE: BEACONHOUSE NATIONAL UNIVERSITY
![Page 2: 7-Refactoring (Object Oriented Software Engineering - BNU Spring 2017)](https://reader037.vdocument.in/reader037/viewer/2022100803/5a65ab327f8b9ab3488b4b69/html5/thumbnails/2.jpg)
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 anyexisting 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
![Page 3: 7-Refactoring (Object Oriented Software Engineering - BNU Spring 2017)](https://reader037.vdocument.in/reader037/viewer/2022100803/5a65ab327f8b9ab3488b4b69/html5/thumbnails/3.jpg)
Principles in Refactoring
FROM: HAFIZ AMMAR SIDDIQUI – COURSE: OBJECT ORIENTED SOFTWARE ENGINEERING – INSTITUTE: BEACONHOUSE NATIONAL UNIVERSITY
![Page 4: 7-Refactoring (Object Oriented Software Engineering - BNU Spring 2017)](https://reader037.vdocument.in/reader037/viewer/2022100803/5a65ab327f8b9ab3488b4b69/html5/thumbnails/4.jpg)
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
![Page 5: 7-Refactoring (Object Oriented Software Engineering - BNU Spring 2017)](https://reader037.vdocument.in/reader037/viewer/2022100803/5a65ab327f8b9ab3488b4b69/html5/thumbnails/5.jpg)
Identifying Bad Smells
FROM: HAFIZ AMMAR SIDDIQUI – COURSE: OBJECT ORIENTED SOFTWARE ENGINEERING – INSTITUTE: BEACONHOUSE NATIONAL UNIVERSITY
![Page 6: 7-Refactoring (Object Oriented Software Engineering - BNU Spring 2017)](https://reader037.vdocument.in/reader037/viewer/2022100803/5a65ab327f8b9ab3488b4b69/html5/thumbnails/6.jpg)
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
![Page 7: 7-Refactoring (Object Oriented Software Engineering - BNU Spring 2017)](https://reader037.vdocument.in/reader037/viewer/2022100803/5a65ab327f8b9ab3488b4b69/html5/thumbnails/7.jpg)
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 explainwhat it does
FROM: HAFIZ AMMAR SIDDIQUI – COURSE: OBJECT ORIENTED SOFTWARE ENGINEERING – INSTITUTE: BEACONHOUSE NATIONAL UNIVERSITY
![Page 8: 7-Refactoring (Object Oriented Software Engineering - BNU Spring 2017)](https://reader037.vdocument.in/reader037/viewer/2022100803/5a65ab327f8b9ab3488b4b69/html5/thumbnails/8.jpg)
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