Refactoring Types Blake Duncan.

Slides:



Advertisements
Similar presentations
Clean code. Motivation Total cost = the cost of developing + maintenance cost Maintenance cost = cost of understanding + cost of changes + cost of testing.
Advertisements

A practical guide John E. Boal TestDrivenDeveloper.com.
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.
Introduction to Refactoring Excerpted from ‘What is Refactoring?’ by William C. Wake and Refactoring: Improving the Design of Existing Code by Martin Fowler.
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.
Code Generation CS 480. Can be complex To do a good job of teaching about code generation I could easily spend ten weeks But, don’t have ten weeks, so.
Using the Properties of Logs. You already learned how to solve simple log equations. Now we are going a step or two farther. These equations are solved.
Topic: Solving Systems of Linear Equations Algebraically.
How do you simplify? Simple Complicated.
Maintenance Refactoring and Code Smells. Where are we? Over the semester we have talked about Software Engineering. The overall goal of software engineering.
Adding and Subtracting Rational Expressions
Designing with Procedures 1. Designing a Program with Procedures If the code for your program is going to be less than one page, normally don’t bother;
CSC 313 – Advanced Programming Topics. Design Pattern Intent  Each design pattern is a tool  Like all tools, have reason for being.
LECTURE 38: REFACTORING CSC 395 – Software Engineering.
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.
Adding and Subtracting Rational Expressions
Warmup Alg 2 19 Mar Warmup Alg 2 20 & 21 Mar 2012.
Refactoring (continued) Source: "Refactoring: Improving the Design of Existing Code", Martin Fowler.
Refactoring1 Refactoring DEPARTMENT OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING CONCORDIA UNIVERSITY February 6, 2009.
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)
Refactoring Deciding what to make a superclass or interface is difficult. Some of these refactorings are helpful. Some research items include Inheritance.
Sec. 1-4 Day 2 HW pg (42-46, 53, 62-63, 67, 71-72)
CS242.  Reduce Complexity  Introduce an intermediate, understandable abstraction  Avoid code duplication  Support subclassing  Hide sequences  Hide.
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.
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.
Module 3. Smells Between Classes Course: Refactoring.
Copyright © 2014, 2010, 2007 Pearson Education, Inc. 1 1 Chapter 9 Quadratic Equations and Functions.
1 Software Maintenance and Evolution CSSE 575: Session 2, Part 1 Refactoring Principles Steve Chenoweth Office Phone: (812) Cell: (937)
Solving Systems of Equations Algebraically Chapter 3.2.
Modern Software Development Using C#.NET Chapter 6: Refactoring.
Interfaces About Interfaces Interfaces and abstract classes provide more structured way to separate interface from implementation
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.
Unit: Wrapping Up 5-4: Factoring Quadratic Expressions Essential Question: How do we factor when the first term isn’t simply “x”? Will animations help.
1 Add Fiscal Year or a Fiscal Year Filter  To add Fiscal Year to a layout.
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.
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 Dealing with Generalization Steve and Shawn Left – In the 1990 movie “The Freshman,” Matthew Broderick,
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.
Module 9. Dealing with Generalization Course: Refactoring.
No Pencil or Paper Needed!.  Make sure you know your multiplication tables up to 10.
Catalog of Refactoring (1) Composing Methods. Code Smells Long methods Dubious temporary variables Dubious methods.
5.7.2 – Complex Numbers. From yesterday, we learned the application of the imaginary unit i Used for problems such as; -5x 2 = 20.
Principles and examples
April 9, 2014 Aim: How do we add and subtract RADICALS? Do Now: Simplify the following radical expressions: 1. 2.
Solving Systems of Equations
simplify radical expressions involving addition and subtraction.
Steve Chenoweth Office Phone: (812) Cell: (937)
Refactoring and Code Smells
Adding and Subtracting Polynomials – Part 2
Solving Systems of Equations
Code Smells 1.
Improving the structure of existing code
Refactoring and Code Smells
Notes Solving a System by Elimination
Objective Use multiplication properties of exponents to evaluate and simplify expressions.
Solving Equations Finding Your Balance
Refactoring.
Refactoring and Code Smells
Refactoring.
Refactoring and Code Smells
Presentation transcript:

Refactoring Types Blake Duncan

Add Parameter Add Parameter is a very common refactoring, one that you almost certainly have already done. The motivation is simple. You have to change a method, and the change requires information that wasn’t passed in before, so you add a parameter.

Add Parameter

Add Parameters Benefit: Con: Allows you to pass more information from the calling method New parameter can be used to simplify implementation or add functionality Con: Often you have other alternatives to adding a parameter. If available, these alternatives are better because they don’t lead to increasing the length of parameter lists. Long parameter lists smell bad because they are hard to remember and often involve data clumps.

Collapse Hierarchy If you have been working for a while with a class hierarchy, it can easily become too tangled for its own good. Refactoring the hierarchy often involves pushing methods and fields up and down the hierarchy. After you’ve done this you can well find you have a subclass that isn’t adding any value, so you need to merge the classes together.

Collapse Hierarchy

Collapse Hierarchy Benefit The program complexity is reduced because there are now fewer classes. Navigating through your code is easier when methods are defined in one class early. You do not need to comb through the entire hierarchy to find a particular method.

Consolidate Conditional Expression Sometimes you see a series of conditional checks in which each check is different yet the resulting action is the same. When you see this, you should use ands and ors to consolidate them into a single conditional check with a single result.

Consolidate Conditional Expression Example

Consolidate Conditional Expression Benefit By consolidating all operators, you can now isolate this complex expression in a new method with a name that explains the conditional's purpose. Eliminates duplicate control flow code. Combining multiple conditionals that have the same "destination" helps to show that you are doing only one complicated check leading to one action.