Refactoring Advanced Software Engineering 603 492 Dr Nuha El-Khalili.

Slides:



Advertisements
Similar presentations
Module 7. Simplifying Conditional Expressions Course: Refactoring.
Advertisements

You want me to do what??? Refactoring legacy applications aka : fixing someone else’s “bad” code Niel Zeeman Team Foundation Consulting
Software Restructuring(Refactoring) Giriprasad Sridhara CISC 879 Spring 2007 May
Refactoring Overview  What is refactoring?  What are four good reasons to refactor?  When should you refactor?  What is a bad smell (relative to refactoring.
REFACTORING. What is refactoring ? In refactoring, you start with the basic code and make it better. Change the internal structure of the existing code.
Software Construction and Evolution - CSSE 375 Bad Smells in Code Shawn Bohner & Steve Chenoweth.
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.
REFACTORING Improving the Design of Existing Code Atakan Şimşek e
Test-Driven Development “Test first, develop later!” –OCUnit.
Maintenance Refactoring and Code Smells. Where are we? Over the semester we have talked about Software Engineering. The overall goal of software engineering.
Refactoring Lecture 5 CIS 6101 Software Processes and Metrics.
Program Refactoring Mitch Soden Union College. Agenda Definition –Unit Testing –Examples Why Refactor? Limitations Just Another SW Eng Practice? Automation.
Advanced Programing practices
Refactoring Cristescu Marilena. Definitions Loose Usage: Reorganize a program(or something) As a noun: a change made to the internal structure of some.
Software Refactoring Part I: Introduction Bartosz Walter Advanced Object-Oriented Design Lecture 5.
Design and Programming Chapter 7 Applied Software Project Management, Stellman & Greene See also:
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.
17-Oct-15 Refactoring. 2 Refactoring is: restructuring (rearranging) code......in a series of small, semantics-preserving transformations (i.e. the code.
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.
Improving the Quality of Existing Code Svetlin Nakov Telerik Corporation
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.
Alcatel-Lucent CDC Workshop, Coaching & Knowledge Transfer Coding.
Encapsulation COMP 401, Fall 2014 Lecture 06 9/4/2014.
Introduction to Refactoring Jim Cooper Falafel Software.
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.
Incremental Design Why incremental design? Goal of incremental design Tools for incremental design  UML diagrams  Design principles  Design patterns.
Software Engineering CS3003 Lecture 4 Code bad smells and refactoring.
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.
Refactoring 2. Admin Blackboard Quiz Acknowledgements Material in this presentation was drawn from Martin Fowler, Refactoring: Improving the Design of.
NJIT 1 Test Driven Development and Refactoring Larman, Chapter 21.
Writing Maintainable code Dr. Susan McKeever DT228/3 GUI Programming.
Refactoring Conditionals Lesson Five: Conditionals.
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
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.
Diagnosing Design Problems in Object Oriented Systems Adrian Trifu, Radu Marinescu Proceedings of the 12th IEEE Working Conference on Reverse Engineering.
Refactoring1 Improving the structure of existing code.
Pertemuan 12 Refactoring Mata kuliah: T0144 – Advanced Topics in Software Engineering Tahun: 2010.
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.
Software Construction and Evolution - CSSE 375 Simplifying Conditionals Shawn & Steve.
CSSE 375 Organizing Data – Part 1 Shawn and Steve Q1.
Test Driven Development Introduction Issued date: 8/29/2007 Author: Nguyen Phuc Hai.
Refactoring. DCS – SWC 2 Refactoring ”A change made to the internal structure of software to make it easier to understand and cheaper to modify without.
Catalog of Refactoring (5) Simplifying Conditional Expressions.
Code Refactoring Milan Vukoje Soprex SkfOffice2 SkfOffice3 Big5 Quality oriented We are hiring…
Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
ICONFINDER ICONFINDER Founded Django based web application -PostgreSQL -Elasticsearch -Amazon Elastic Compute.
Mapping Designs to Code. It specify how to map the design into object oriented language The UML artifacts created during the design work, the interaction.
Principles and examples
Module Road Map Refactoring Why Refactoring? Examples
A Very Common Series of Techniques
Dilbert Scott Adams Manage It! Your Guide to Modern, Pragmatic Project Management. Johanna Rothman.
Refactoring and Code Smells
Overview of Eclipse Lectures
Code Smells 1.
Improving the structure of existing code
Refactoring and Code Smells
Advanced Programming Behnam Hatami Fall 2017.
Refactoring Strategies
Refactoring.
Refactoring and Code Smells
Advanced Programing practices
Refactoring.
Refactoring and Code Smells
Presentation transcript:

Refactoring Advanced Software Engineering Dr Nuha El-Khalili

What is Refactoring? Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. 2

Refactoring Done by applying series of "refactorings", each of which is tiny change in a source code Each transformation does little, but a sequence of transformations can produce a significant restructuring. The system is kept fully working after each small refactoring 3

Advantages Improved code readability Reduced complexity Improve the maintainability 4

Code smell Any symptom in the source code of a program that possibly indicates a deeper problem Common code smells – Duplicated code: identical or very similar code exists in more than one location. – Long method: a method, function, or procedure that has grown too large. – Large class: a class that has grown too large. – Too many parameters: a long list of parameters in a procedure or function that reduce readability

Code smell Common code smells – Feature envy: a class that uses methods of another class excessively. – Refused bequest: a class that overrides a method of a base class in such a way that the contract of the base class is not honored by the derived class. – Lazy class / Freeloader: a class that does too little. – Excessively long identifiers: naming conventions provide disambiguation – Excessively short identifiers: the name of a variable should reflect its function unless it's obvious. – Excessive use of literals: these should be coded as named constants, to improve readability

Refactoring Techniques Techniques for breaking code apart – Extract Method, to turn part of a larger method into a new method – Extract Class moves part of the code from an existing class into a new class Techniques that allow for more abstraction – Encapsulate Field – force code to access the field with getter and setter methods – Generalize Type – create more general types to allow for more code sharing

Refactoring Techniques Organizing Data – Replace Magic Number with Symbolic Constant – Encapsulate Field Simplifying Conditional Expression Moving Features Between Objects – Changing of decisions regarding where to put reponsibilities Making Method Calls Simpler – Creating more straightforward interfaces

Extract Method void printOwing(double amount) { printBanner(); // print details std::cout << “name” << _name << std::endl; std::cout << “amount” << _amount << std::endl; } /*************************************************************/ void printOwing(double amount) { printBanner(); printDetails(); } void printDetails(double amount) { std::cout << “name” << _name << std::endl; std::cout << “amount” << _amount << std::endl; }

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);

When should we refactor? When we add new functionality When we fix a bug When we do a code review

Refactoring and Unit Tests Relationship between refactoring and Unit tests (?) Refactoring is strongly dependent on having a good suite of unit tests With the unit tests, we can refactor Then run the automated tests –T–To verify that the behaviour is indeed preserved. Without good unit tests, –d–developers may shy away from refactoring –D–Due to the fear that they may break something. 12

Refactoring problems and limitations Interfaces: – Refactoring techniques like RenameMethod – change a published interface. Databases: – Many applications have code that is tightly coupled with an underlying database schema.

Tools For Visual Studio 2010, download – Code Rush Xpress – Supports VB and C# refactor