Download presentation
Presentation is loading. Please wait.
Published byEzra Fitzgerald Modified over 6 years ago
1
Software Engineering Modern Approaches Chapter 24. Refactoring
2
Using a Refactoring Wizard
Shift/Alt/R © 2010 John Wiley & Sons Ltd.
3
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.
4
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.
5
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.
6
Big Refactorings 2*: Convert Procedural Design to Objects
before Control startGame() displayCharacter() moveCharacter() VideoGame GameCharacter *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.
7
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.
8
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.
9
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.
10
Big Refactorings 4*: Extract Hierarchy
before Project *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.
11
Big Refactorings 4*: Extract Hierarchy
before Project after Project SoftwareEngineeringProject CustomerEntertainmentProject MobileApplication DesktopApplication *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.
12
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.
13
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.
14
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.
15
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.
16
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.
17
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.
18
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.
19
Dealing with Generalization 4*: Form Template Method
BicycleAssemblyInstructions writeBikeInstructions() TricycleAssemblyInstructions writeTrikeInstructions() *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.
20
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.
21
Fowler: Dealing with Generalization*
Replace Inheritance with Delegation Replace Delegation with Inheritance Record lastChanged() Account *Fowlers’ taxonomy © 2010 John Wiley & Sons Ltd.
22
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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.