Refactoring. 2 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.

Slides:



Advertisements
Similar presentations
12-Dec-14 Refactoring IV. Previously discussed bad smells Duplicated code — and other forms of redundancy Long method — use short methods that delegate.
Advertisements

Module 7. Simplifying Conditional Expressions Course: Refactoring.
Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
© 2010 Shawn A. Bohner Software Construction and Evolution - CSSE 375 Even more Bad Smells in Code Shawn & Steve Q1 Shawn & Steve Hint 
You want me to do what??? Refactoring legacy applications aka : fixing someone else’s “bad” code Niel Zeeman Team Foundation Consulting
Gregor Gisler-Merz BrownBag Session Refactoring.
Refactoring Overview  What is refactoring?  What are four good reasons to refactor?  When should you refactor?  What is a bad smell (relative to refactoring.
Software Construction and Evolution - CSSE 375 Bad Smells in Code Shawn Bohner & Steve Chenoweth.
1 Software Maintenance and Evolution CSSE 575: Session 3, Part 4 Big Refactorings Steve Chenoweth Office Phone: (812) Cell: (937)
1 Software Maintenance and Evolution CSSE 575: Session 1, Part 4 Even more Bad Smells in Code Steve Chenoweth Office Phone: (812) Cell: (937)
Steve Chenoweth Office Phone: (812) Cell: (937)
Test-Driven Development and Refactoring Project 3 Lecture 1 CPSC 315 – Programming Studio Fall 2009.
Introduction to Refactoring Excerpted from ‘What is Refactoring?’ by William C. Wake and Refactoring: Improving the Design of Existing Code by Martin Fowler.
George Blank University Lecturer. REFACTORING Improving the Design of Existing Code Supplement to Ian Sommerville, Software Engineering, Chapter 20 Prepared.
XP and Refactoring David Talby. Development Methodologies The Software Crisis – 84% of software projects are not on time – 31% of software projects never.
REFACTORING Improving the Design of Existing Code Atakan Şimşek e
1 v1.6 08/02/2006 Overview of Eclipse Lectures 1.Overview 2.Installing and Running 3.Building and Running Java Classes 4.Refactoring 5.Debugging 6.Testing.
What is Refactoring? CSE301 University of Sunderland Harry R. Erwin, PhD.
Advanced Programing practices
Software Refactoring Part I: Introduction Bartosz Walter Advanced Object-Oriented Design Lecture 5.
Sadegh Aliakbary Sharif University of Technology Spring 2012.
Chapter 6: Code Refactoring Omar Meqdadi SE 3860 Lecture 6 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Software Engineering Modern Approaches Eric Braude and Michael Bernstein 1.
Refactoring. Mathematics: Factor ● fac·tor – One of two or more quantities that divides a given quantity without a remainder, e.g., 2 and 3 are factors.
Software Engineering 1 Object-oriented Analysis and Design Chap 21 Test-Driven Development and Refactoring.
Refactoring Improving the structure of existing code Refactoring1.
Small changes to code to improve it. Refactoring Defined A change made to the internal structure of software to make it easier to understand and cheaper.
Refactoring1 Refactoring DEPARTMENT OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING CONCORDIA UNIVERSITY February 6, 2009.
SWE 316: Software Design and Architecture Objectives Lecture # 20 Improving the existing design: Refactoring SWE 316: Software Design and Architecture.
1 Software Maintenance and Evolution CSSE 575: Session 3, Part 1 Simplifying Conditionals Steve Chenoweth Office Phone: (812) Cell: (937)
Refactoring1 Improving the structure of existing code.
The effectiveness of refactoring based on a compatibility testing taxonomy and a dependency graph Steve Counsell and Robert Hierons, Brunel University,
1 CSC/ECE 517 Fall 2010 Lec. 3 Overview of Eclipse Lectures Lecture 2 “Lecture 0” Lecture 3 1.Overview 2.Installing and Running 3.Building and Running.
Refactoring and such ● (Side note) Specialization ● Key terms ● Abstraction, state, persistence and association and their relationship to software development.
Refactoring: Code Smells. Admin Notes REGISTER FOR BLACKBOARD Watch blackboard site for updates on class as hurricane season approaches.
Refactoring. Refactoring Overview  What is refactoring?  What are four good reasons to refactor?  When should you refactor?  What is a bad smell (relative.
Chapter 21 Test-Driven Development 1CS6359 Fall 2011 John Cole.
E L EARNING E NVIRONMENT FOR S OFTWARE E NGINEERING E DUCATION (R EFACTORING A GENT ) A.Stoyanova-Doycheva University of Plovdiv г. 10th Workshop.
Refactoring 2. Admin Blackboard Quiz Acknowledgements Material in this presentation was drawn from Martin Fowler, Refactoring: Improving the Design of.
REFACTORINGREFACTORING. Realities Code evolves substantially during development Requirements changes 1%-4% per month on a project Current methodologies.
NJIT 1 Test Driven Development and Refactoring Larman, Chapter 21.
Module 3. Smells Between Classes Course: Refactoring.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Refactoring Conditionals Lesson Five: Conditionals.
1 Software Maintenance and Evolution CSSE 575: Session 2, Part 1 Refactoring Principles Steve Chenoweth Office Phone: (812) Cell: (937)
Software Construction and Evolution - CSSE 375 Making Method Calls Simpler Shawn and Steve Below – “Be the character!” The late acting teacher Lee Strasberg.
1 Software Maintenance and Evolution CSSE 575: Session 3, Part 3 Dealing with Generalization Steve Chenoweth Office Phone: (812) Cell: (937)
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
Refactoring Advanced Software Engineering Dr Nuha El-Khalili.
Refactoring. Mathematics: Factor ● fac·tor – One of two or more quantities that divides a given quantity without a remainder, e.g., 2 and 3 are factors.
Small changes to code to improve it. Refactoring Defined A change made to the internal structure of software to make it easier to understand and cheaper.
Refactoring1 Improving the structure of existing code.
Pertemuan 12 Refactoring Mata kuliah: T0144 – Advanced Topics in Software Engineering Tahun: 2010.
Software Construction and Evolution - CSSE 375 Simplifying Conditionals Shawn & Steve.
CSSE 375 Organizing Data – Part 1 Shawn and Steve Q1.
Module 9. Dealing with Generalization Course: Refactoring.
Catalog of Refactoring (5) Simplifying Conditional Expressions.
Code Refactoring Milan Vukoje Soprex SkfOffice2 SkfOffice3 Big5 Quality oriented We are hiring…
Principles and examples
Steve Chenoweth Office Phone: (812) Cell: (937)
Module Road Map Refactoring Why Refactoring? Examples
Small changes to code to improve it
Overview of Eclipse Lectures
Improving the structure of existing code
Small changes to code to improve it
Advanced Programming Behnam Hatami Fall 2017.
Refactoring Strategies
Advanced Programing practices
Refactoring.
Presentation transcript:

Refactoring

2 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 [Fowler'99] A program restructuring operation to support the design, evolution, and resuse of object oriented frameworks that preserve the behaviorial aspects of the program [Opdyke'92]

3 Specifics Source to source transformation Remain inside the same language, e.g., C++ to C++ Does not change the programs behavior – according to a test suite Originally designed for object-oriented languages, but can also be applied to non-object oriented language features, i.e., functions

4 Levels of Software Changes High Level -  Features to be added to a system  e.g., New a new menu, or menu item Intermediate Level  Change design (factoring)  e.g., Move a member function Low Level  Change lines of code  e.g., Changes in (a least) two classes

5 Some Example Refactorings Introduce Explaining Variable Rename Method Move Method Pullup Method Change Value to Reference Remove Parameter Extract Hierarchy

6 When? Adding Functionality  Comprehension of existing program  Preparation for addition Debugging  Comprehension of existing program Code Review  Preparation for suggestions to other programmers  Stimulates other ideas

7 Categories Composing Methods  Creating methods out of inlined code Moving Features Between Objects  Changing of decisions regarding where to put reponsibilities Organizing Data  Make working with data easier

8 Categories (cont) Simplifying Conditional Expressions Making Method Calls Simpler  Creating more straightforward interfaces Dealing with Generalization  Moving methods around within hierarchies Big Refactorings  Refactoring for larger purposes

9 Moving Object Features Move Method Move Field Extract Class Remove Middle Man Introduce Foreign Method Introduce Local Extension

10 Organizing Data Self Encapsulate Field Replace Data Value with Object Change Value to Reference Change Reference to Value Replace Array with Object Duplicate Observed Data Change Unidirectional Association to Bidirectional Change Bidirectional Association to Unidirectional

11 Simplifying Conditional Decompose Conditional Consolidate Conditional Expression Consolidate Duplicate Conditional Fragments Remove Control Flag Replace Nested Conditional with Guard Clauses Replace Conditional with Polymorphism Introduce Null Object Introduce Assertion

12 Example: Decompose Conditional if (date.before (SUMMER_START) || date.after(SUMMER_END)) charge = quantity * _winterRate + _winterServiceCharge; else charge = quantity * _summerRate; if (notSummer(date)) charge = winterCharge(quantity); else charge = summerCharge(quantity);

13 Simplifying Method Calls Rename Method Add Parameter Remove Parameter Seperate Query from Modifier Parameterize Method Replace Parameter with Explicit Methods Preserve Whole Object Replace Parameter with Method

14 Example: Push Down Method

15 Example: Extract Subclass