Refactoring Cristescu Marilena. Definitions Loose Usage: Reorganize a program(or something) As a noun: a change made to the internal structure of some.

Slides:



Advertisements
Similar presentations
A practical guide John E. Boal TestDrivenDeveloper.com.
Advertisements

You want me to do what??? Refactoring legacy applications aka : fixing someone else’s “bad” code Niel Zeeman Team Foundation Consulting
Refactoring and Code Smells
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 By: Brian Smith. What is Refactoring? Definition: a change to the internal structure of software to make it easier to understand and cheaper.
Introduction to Refactoring Excerpted from ‘What is Refactoring?’ by William C. Wake and Refactoring: Improving the Design of Existing Code by Martin Fowler.
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
12-Jul-15 Refactoring. 2 Refactoring is: restructuring (rearranging) code......in a series of small, semantics-preserving transformations (i.e. the code.
Design, Implementation and Maintenance
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 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Advanced Programing practices
Software Refactoring Part I: Introduction Bartosz Walter Advanced Object-Oriented Design Lecture 5.
Sadegh Aliakbary Sharif University of Technology Spring 2012.
Refactoring - A disciplined approach to rework for better design.
TOOLS FOR DESIGN AND DEVELOPMENT ENVIRONMENTS. Case study - ECLIPSE Lecture notes 7.
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.
When and How to Refactor? Refactoring Patterns Alexander Vakrilov Telerik Corporation Senior Developer and Team Leader.
Improving the Quality of Existing Code Svetlin Nakov Telerik Corporation
Refactoring An Automated Tool for the Tiger Language Leslie A Hensley
Refactoring1 Improving the structure of existing code.
Refactoring Deciding what to make a superclass or interface is difficult. Some of these refactorings are helpful. Some research items include Inheritance.
Advanced Programming in Java
Informatics 122 Software Design II
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.
REFACTORINGREFACTORING. Realities Code evolves substantially during development Requirements changes 1%-4% per month on a project Current methodologies.
Writing Maintainable code Dr. Susan McKeever DT228/3 GUI Programming.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
1 Software Maintenance and Evolution CSSE 575: Session 2, Part 1 Refactoring Principles Steve Chenoweth Office Phone: (812) Cell: (937)
Refactoring - 1 CS494: Intro. to Refactoring Readings: –Refactoring for everyone: How and why to use Eclipse's automated refactoring features. By David.
Modern Software Development Using C#.NET Chapter 6: Refactoring.
Refactoring Mehdi Einali Advanced Programming in Java 1.
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
Refactoring Advanced Software Engineering Dr Nuha El-Khalili.
CSSE 375 Organizing Data – Part 2 Shawn and Steve Continue the same quiz!
Refactoring1 Improving the structure of existing code.
Refactoring Agile Development Project. Lecture roadmap Refactoring Some issues to address when coding.
Pertemuan 12 Refactoring Mata kuliah: T0144 – Advanced Topics in Software Engineering Tahun: 2010.
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.
Refactoring: Improving the Design of Existing Code.
10-Jun-16.  Refactoring is: ◦ restructuring (rearranging) code... ◦...in a series of small, semantics-preserving transformations (i.e. the code keeps.
Principles and examples
Module Road Map Refactoring Why Refactoring? Examples
Steve Chenoweth Office Phone: (812) Cell: (937)
A Very Common Series of Techniques
Advanced Programming in Java
Refactoring and Code Smells
Code Smells 1.
Improving the structure of existing code
Refactoring and Code Smells
Advanced Programming Behnam Hatami Fall 2017.
Refactoring.
Refactoring and Code Smells
Advanced Programing practices
Refactoring and Code Smells
Refactoring.
Refactoring and Code Smells
Presentation transcript:

Refactoring Cristescu Marilena

Definitions Loose Usage: Reorganize a program(or something) As a noun: a change made to the internal structure of some software to make it easier to understand and cheaper to modify, without changing the observable behavior of that software As a verb: the activity of restructuring software by applying a series of refactorings without changing the observable behavior of that software

What is Refactoring? A series of small steps, each of which changes the program’s internal structure without changing its external behavior – Martin Fowler Verify no change in external behavior by: – Testing – Using the right tool – IDE – Formal code analysis by tool – Being very, very careful

Why do we Refactor? Helps us deliver more business value faster Improves the design of our software: – Easier to maintain and understand – Easier to facilitate change – More flexibility – Increase re-usability Minimizes technical dept Keep development at speed To make the software easier to understand To help find bugs To “Fix broken windows” – Pragmatic Programmers

When should we Refactor? To add new functionality To find bugs For code reviews For TDD (Test, Code, Refactor)

Team Techniques Encourage refactoring culture – Nobody gets things right the first time – Nobody can write clear code without reviews – Refactoring is progress Provide sound testing base – Tests are essential for refactoring – Build system and run tests daily Pair Programming – Two programmers working together can be quicker than working separately – Refactor with the class writer and a class user

How do we Refactor? We look for Code-Smells Things that we suspect are not quite right or cause us severe pain if we do not fix

Common Code Smells Duplicated code Feature Envy Comments Long Method Long Parameter List Switch Statements Improper Naming

Some Refactorings

Move Method A method is, or will be, using or used by more features of another class than the class on which it is defined. Create a new method with a similar body in the class it uses most. Either turn the old method into a simple delegation, or remove it altogether.

Extract Class You have one class doing work that should be done by two. Create a new class and move the relevant fields and methods from the old class into the new class.

Replace Magic Number with Symbolic Constant You have a literal number with a particular meaning. Create a constant, name it after the meaning, and replace the number with it.. double potentialEnergy(double mass, double height) { return mass * 9.81 * height; } double potentialEnergy(double mass, double height) { return mass * GRAVITATIONAL_CONSTANT * height; } static final double GRAVITATIONAL_CONSTANT = 9.81;

Replace Subclass with Fields You have subclasses that vary only in methods that return constant data. Change the methods to superclass fields and eliminate the subclasses.

Rename Method The name of a method does not reveal its purpose. Change the name of the method.

Parameterize Method Several methods do similar things but with different values contained in the method body. Create one method that uses a parameter for the different values.

Pull Up Field Two subclasses have the same field. Move the field to the superclass.

Separate Domain from Presentation You have GUI classes that contain domain logic. Separate the domain logic into separate domain classes

Database Refactoring A database refactoring is a simple change to a database schema that improves its design while retaining both its behavioral and informational semantics Database Smells: – stored code: Monster Procedures, Spaghetti, Duplication, IF-ELSE overuse, low cohesion – Database schema: Multi-purpose table / column, Redundant data, Tables with many columns / rows, Lack of constraints

Bibliography Martin Fowler: Refactoring: Improving the Design of Existing Code, Addison–Wesley. oring