Software Engineering Modern Approaches Chapter 24. Refactoring.

Slides:



Advertisements
Similar presentations
REFACTORING & SOFTWARE TESTING. Refactoring  Refactoring is the process of altering source code so as to leave its existing functionality unchanged.
Advertisements

You want me to do what??? Refactoring legacy applications aka : fixing someone else’s “bad” code Niel Zeeman Team Foundation Consulting
Refactoring Overview  What is refactoring?  What are four good reasons to refactor?  When should you refactor?  What is a bad smell (relative to refactoring.
1 Software Maintenance and Evolution CSSE 575: Session 3, Part 4 Big Refactorings Steve Chenoweth Office Phone: (812) Cell: (937)
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 1 CS 125 Introduction to Computers and Object- Oriented Programming.
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
Copyright 2008 by Pearson Education Building Java Programs Chapter 9 Lecture 9-1: Inheritance reading:
What is Refactoring? CSE301 University of Sunderland Harry R. Erwin, PhD.
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.
Refactoring Improving the structure of existing code Refactoring1.
Object Orientation Yaodong Bi, Ph.D. Department of Computer Sciences University of Scranton October 18, 2015October 18, 2015October 18, 2015.
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.
SWE 316: Software Design and Architecture Objectives Lecture # 20 Improving the existing design: Refactoring SWE 316: Software Design and Architecture.
Domain Modeling Part2: Domain Class Diagram Chapter 4 pp part 2 1.
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.
Refactoring and such ● (Side note) Specialization ● Key terms ● Abstraction, state, persistence and association and their relationship to software development.
Refactoring. Refactoring Overview  What is refactoring?  What are four good reasons to refactor?  When should you refactor?  What is a bad smell (relative.
Today’s Agenda  More refactoring patterns Software Testing and Maintenance 1.
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.
Refactoring II Dealing with Polymorphism. Switch in Rental Switches on Movie! class Rental … public double getCharge() { double result = 0; switch (getMovie().getPriceCode()){
Module 3. Smells Between Classes Course: Refactoring.
How and When to do Refactoring CSE301 University of Sunderland Harry R. Erwin, PhD.
MIT AITI 2004 – Lecture 13 Abstract Classes and Interfaces.
1 Software Maintenance and Evolution CSSE 575: Session 3, Part 3 Dealing with Generalization Steve Chenoweth Office Phone: (812) Cell: (937)
Object Oriented Programming: Inheritance Chapter 9.
Object Orientation Yaodong Bi, Ph.D. Department of Computer Sciences University of Scranton January 12, 2016January 12, 2016January 12, 2016.
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.
CSSE 375 Organizing Data – Part 2 Shawn and Steve Continue the same quiz!
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.
CET203 SOFTWARE DEVELOPMENT Session 2A Inheritance (programming in C#)
CS100A, 15 Sept Lecture 5 1 CS100A, 5 Sept This lecture continues the discussion of classes. The important new concept of this lecture is.
CSSE 375 Organizing Data – Part 1 Shawn and Steve Q1.
CS100A, Fall Lecture 5 1 CS100A, Fall 1997 Lecture, Tuesday, 16 September. This lecture continues the discussion of classes. The important new concept.
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.
Object Orientation Yaodong Bi, Ph.D. Department of Computer Sciences University of Scranton August 19, 2005.
Principles and examples
Catalog of Refactoring
Object Oriented Programming: Inheritance
Steve Chenoweth Office Phone: (812) Cell: (937)
DATA REQIREMENT ANALYSIS
CMPE 135: Object-Oriented Analysis and Design October 3 Class Meeting
Building Java Programs Chapter 9
Steve Chenoweth, RHIT Ch 12 in Fowler
Object Orientation Yaodong Bi, Ph.D. Department of Computer Sciences
Abstract Classes.
Domain Class Diagram Chapter 4 Part 2 pp
Object-Oriented Programming: Polymorphism
Code Smells 1.
Improving the structure of existing code
Chapter 7 Polymorphism.
Systems Analysis – ITEC 3155 Modeling System Requirements – Part 2
Law firm employee analogy
Lecture 14: Inheritance Building Java Programs: A Back to Basics Approach by Stuart Reges and Marty Stepp Copyright (c) Pearson All rights reserved.
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Refactoring.
Presentation transcript:

Software Engineering Modern Approaches Chapter 24. Refactoring

Using a Refactoring Wizard Shift/Alt/R © 2010 John Wiley & Sons Ltd.

Fowler’s Refactoring Taxonomy Big Refactorings Composing Methods Moving Features Between Objects Organizing Data Dealing With Generalization Simplifying Conditional Expressions Making Method Calls Simpler © 2010 John Wiley & Sons Ltd.

Big Refactorings 1: Tease Apart Inheritance * Employee before SoftwareEmp MaintceEmp ClericalEmp FulltimeSoftwareEmp FulltimeMaintceEmp FulltimeClericalEmp ParttimeSoftwareEmp ParttimeMaintceEmp ParttimeClericalEmp RetiredSoftwareEmp RetiredMaintceEmp RetiredClericalEmp *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.

Big Refactorings 1: Tease Apart Inheritance * Employee before SoftwareEmp MaintceEmp ClericalEmp FulltimeSoftwareEmp FulltimeMaintceEmp FulltimeClericalEmp ParttimeSoftwareEmp ParttimeMaintceEmp ParttimeClericalEmp RetiredSoftwareEmp RetiredMaintceEmp RetiredClericalEmp after  Employee Status SoftwareEmp MaintceEmp ClericalEmp Fulltime Parttime Retired *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.

Big Refactorings 2*: Convert Procedural Design to Objects before Control startGame() displayCharacter() moveCharacter() VideoGame GameCharacter *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.

Big Refactorings 2*: Convert Procedural Design to Objects before Control startGame() displayCharacter() moveCharacter() VideoGame GameCharacter after GameCharacter display() move()  VideoGame start() *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.

Big Refactorings 3*: Separate Domain from Presentation Account name balance … displayStandard() displayHTML() Big Refactorings 3*: Separate Domain from Presentation before *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.

Big Refactorings 3*: Separate Domain from Presentation Account name balance … displayStandard() displayHTML() Big Refactorings 3*: Separate Domain from Presentation before StandardAccountGUI display () after Account name balance …  HTMLAccountGUI display () *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.

Big Refactorings 4*: Extract Hierarchy before Project *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.

Big Refactorings 4*: Extract Hierarchy before Project after Project  SoftwareEngineeringProject CustomerEntertainmentProject MobileApplication DesktopApplication *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.

Organizing Data 3* Replace Record with Data Class Simplest object with private data field, accessor Replace Type Code with Class Account … type before AccountType REGULAR: AccountType BIG_DISCOUNT: AccountType SMALL_DISCOUNT: AccountType Account … after *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.

Replace Type Code with Subclass Organizing Data 4* Replace Type Code with Subclass Replace Type Code with State/Strategy Account … type Account … type *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.

WholesaleAccountType Organizing Data 4* Replace Type Code with Subclass Replace Type Code with State/Strategy Account … Account … type  RegularAccount WholesaleAccount Account … AccountType … Account … type  RegularAccountType WholesaleAccountType *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.

Dealing with Generalization 2* Extract Subclass Extract Superclass Order quantity discount minimum type Manager name salary numSupervisees  Engineer name salary skillSet *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.

Dealing with Generalization 2* Order quantity Extract Subclass Extract Superclass Order quantity discount minimum type  WholesaleOrder discount minimum Employee name salary Manager name salary numSupervisees  Engineer name salary skillSet Manager numSupervisees Engineer skillSet *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.

Dealing with Generalization 3* Extract Interface Collapse Hierarchy Inherited class not special enough Manager name salary numSupervisees billRate Engineer name salary skillSet billRate *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.

Dealing with Generalization 3* Extract Interface Collapse Hierarchy Inherited class not special enough Employee getName() getSalary() Billable getRate() Manager name salary numSupervisees billRate Engineer name salary skillSet billRate  Manager numSupervisees Engineer skillSet *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.

Dealing with Generalization 4*: Form Template Method BicycleAssemblyInstructions writeBikeInstructions() TricycleAssemblyInstructions writeTrikeInstructions() *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.

Dealing with Generalization 4*: Form Template Method AssemblyInstructions writePrep() writeSafety() writeWrapUp() writeManual() Dealing with Generalization 4*: Form Template Method BicycleAssemblyInstructions writePrep() writeSafety() writeWrapUp() BicycleAssemblyInstructions writeBikeInstructions()  TricycleAssemblyInstructions writeTrikeInstructions() TricycleAssemblyInstructions writePrep() writeSafety() writeWrapUp() *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.

Fowler: Dealing with Generalization* Replace Inheritance with Delegation Replace Delegation with Inheritance Record lastChanged() Account *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.

Fowler: Dealing with Generalization* Replace Inheritance with Delegation Replace Delegation with Inheritance Record lastChanged() record.lastChanged()  Account record Account lastChanged() Record lastChanged() *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.