Click here to load reader
Upload
hafiz-ammar-siddiqui
View
121
Download
1
Embed Size (px)
Citation preview
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 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
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 explainwhat 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