SlideShare a Scribd company logo
1 of 30
Introduction to Refactoring
About Me VorleakChy Email (vorleak.chy@gmail.com) Yoolk Inc. (http://www.yoolk.com) Blog (http://vorleakchy.com) Rails Developer .NET Developer
What do we talk about Refactoring? What?  Why?  When?  How?
Get Agile – Refactoring Practices Tools
What is Refactoring? The 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 structure. Fowler, et al., Refactoring, 1999.
Before After Easier to understand Clean code Better code Cheaper to modify … More Unreadable code Duplicated code Complex code Hard to modify … More
Why do we Refactor? The reality Extremely difficult to get the design “right” the first time Hard to fully understand the problem domain Hard to understand user requirements, even if the user does! Hard to know how the system will evolve in five years Original design is often inadequate System becomes brittle over time, and more difficult to change
Why do we Refactor? (Cont.) Helps us to deliver more business values faster Improve code structure and design Easier to maintain and understand Easier to modify More flexibility Easier to add new features Increased re-usability
Why do we Refactor?(Cont.) Keep development at speed To make the software easier to understand Write for people, not the compiler Understand unfamiliar code To help us find bugs Refactor while debugging to clarify the code
Readability Which code segment is easier to read? Sample 1 if (date.before(Summer_Start) || date.after(Summer_End)) 	charge = quantity * winterRate + winterServiceCharge; else 	charge = quantity * summerRate; Sample 2 if (isSummer(date)) 	charge = summerCharge(quantity); else 	charge = winterCharge(quantity);
When should werefactor? Add new features Fix bugs During code review Only refactor when refactoring. Do not add features during refactoring
When Not to Refactor Sometimes you should throw things out and start again Sometimes you are too close to a deadline
Costs of Not Refactoring Bad code usually takes more code to do the same thing often because of duplication
How do we Refactor? We looks for Code-Smells Things that we suspect are not quite right or will cause us severe pain if we do not fix
Common Code Smells Duplicated code Feature Envy Comments Long Method Long parameter list Switch Statements
Duplicated code There is obvious duplication Such as copy and paste There are unobvious duplications Such as parallel inheritance hierarchies Similar algorithms Remedy Extract Method Pull Up Field
Feature Envy A method that seems more interested in some other classes than the one it is in Remedy Move Method Extract Method
Extract Method void printOwning(double amount){ printBanner(); 	// print details System.Console.WriteLine(string.Format(“name: “, name); System.Console.WriteLine(string.Format(“amount: “, amount); } void printOwning(double amount){ printBanner(); printDetails(amount); } void printDetails(double amount){ System.Console.WriteLine(string.Format(“name: “, name); System.Console.WriteLine(string.Format(“amount: “, amount); }
Comments Comments – be suspicious! Comments represent a failure to express an idea in the code Remedy Extract Method Rename Method
Long Method Good OO code is easiest to understand and maintain with shorter methods with good names Long methods tend to be harder to read and understand Remedy Extract Method Replace Temp with Query Replace Method with Method Object Decompose Conditional
Replace Temp with Query double basePrice = _quanity* 		_itemPrice; if(basePrice> 1000) { 	return basePrice * 0.95; } else { 	return basePrice * 0.98; } if(getBasePrice() > 1000) { 	return getBasePrice() * 0.95; } else { 	return getBasePrice() * 0.98; } double getBasePrice() { 	return _quanitiy * _itemPrice; }
Long parameter list Functions should have as few parameters as possible Remedy Replace Parameter with Method Preserve Whole Object Introduce Parameter Object
Introduce Parameter Object Customer Customer amountInvoicedIn(Date start, Date end) amountRecivedIn(Date start, Date end) amountOverdueIn(Date start, Date end) amountInvoicedIn(DateRangerange) amountRecivedIn(DateRangerange) amountOverdueIn(DateRangerange)
Switch Statements Type cases are evil because they tend to be duplicated many times Remedy Replace Type Code with Subclasses Replace Type Code with State / Strategy Replace Conditional with Polymorphism Replace Parameter with Explicit Methods Introduce Null Object
Replace Parameter with Explicit Methods void setValue(String name, int value) { 	if(name.Equals(“height”)) 	{ _height = value; return; 	} 	if(name.Equals(“width”)) 	{ 	         _width = value;                  return;          } } void setHeight(intvalue) { 	_height = value; } void setWidth(intvalue) { 	_width = value; }
Refactoring Cycle Choose on appropriate Refactoring to apply Apply Refactoring Run ALL Tests (Get GREEN Bar) Reached Desired Structure? No Yes
Demo
Q & A
Essential Reading
Thank you!

More Related Content

Viewers also liked

Method-Level Code Clone Modification using Refactoring Techniques for Clone M...
Method-Level Code Clone Modification using Refactoring Techniques for Clone M...Method-Level Code Clone Modification using Refactoring Techniques for Clone M...
Method-Level Code Clone Modification using Refactoring Techniques for Clone M...acijjournal
 
Patricia Deshane - PhD Dissertation
Patricia Deshane - PhD DissertationPatricia Deshane - PhD Dissertation
Patricia Deshane - PhD DissertationPatricia Deshane
 
E-LEARNING FOR ALL WITH INTERFACE INCORPORATING KNOWLEDGE ABOUT USER
E-LEARNING FOR ALL WITH INTERFACE INCORPORATING KNOWLEDGE ABOUT USER E-LEARNING FOR ALL WITH INTERFACE INCORPORATING KNOWLEDGE ABOUT USER
E-LEARNING FOR ALL WITH INTERFACE INCORPORATING KNOWLEDGE ABOUT USER acijjournal
 

Viewers also liked (8)

PhD Dissertation
PhD DissertationPhD Dissertation
PhD Dissertation
 
FSE DS
FSE DSFSE DS
FSE DS
 
Method-Level Code Clone Modification using Refactoring Techniques for Clone M...
Method-Level Code Clone Modification using Refactoring Techniques for Clone M...Method-Level Code Clone Modification using Refactoring Techniques for Clone M...
Method-Level Code Clone Modification using Refactoring Techniques for Clone M...
 
ICPC
ICPCICPC
ICPC
 
Patricia Deshane - PhD Dissertation
Patricia Deshane - PhD DissertationPatricia Deshane - PhD Dissertation
Patricia Deshane - PhD Dissertation
 
ICPC Demo
ICPC DemoICPC Demo
ICPC Demo
 
PhD Proposal
PhD ProposalPhD Proposal
PhD Proposal
 
E-LEARNING FOR ALL WITH INTERFACE INCORPORATING KNOWLEDGE ABOUT USER
E-LEARNING FOR ALL WITH INTERFACE INCORPORATING KNOWLEDGE ABOUT USER E-LEARNING FOR ALL WITH INTERFACE INCORPORATING KNOWLEDGE ABOUT USER
E-LEARNING FOR ALL WITH INTERFACE INCORPORATING KNOWLEDGE ABOUT USER
 

Similar to Introduction to Refactoring

Refactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerRefactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerIgor Crvenov
 
Agile_goa_2013_clean_code_tdd
Agile_goa_2013_clean_code_tddAgile_goa_2013_clean_code_tdd
Agile_goa_2013_clean_code_tddSrinivasa GV
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And RefactoringNaresh Jain
 
Refactoring PHP
Refactoring PHPRefactoring PHP
Refactoring PHPAdam Culp
 
Software Craftsmanship - 2
Software Craftsmanship - 2Software Craftsmanship - 2
Software Craftsmanship - 2Uri Lavi
 
Refactoring: Improve the design of existing code
Refactoring: Improve the design of existing codeRefactoring: Improve the design of existing code
Refactoring: Improve the design of existing codeValerio Maggio
 
Ddc2011 효과적으로레거시코드다루기
Ddc2011 효과적으로레거시코드다루기Ddc2011 효과적으로레거시코드다루기
Ddc2011 효과적으로레거시코드다루기Myeongseok Baek
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoringkim.mens
 
Bad Smell in Codes - Part 1
Bad Smell in Codes - Part 1Bad Smell in Codes - Part 1
Bad Smell in Codes - Part 1Shaer Hassan
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataCory Foy
 
Refactoring and code smells
Refactoring and code smellsRefactoring and code smells
Refactoring and code smellsPaul Nguyen
 
En story of cakephp2.0
En story of cakephp2.0En story of cakephp2.0
En story of cakephp2.0Hiroki Shimizu
 
Naming Standards, Clean Code
Naming Standards, Clean CodeNaming Standards, Clean Code
Naming Standards, Clean CodeCleanestCode
 
C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2Hammad Rajjoub
 

Similar to Introduction to Refactoring (20)

Refactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerRefactoring Tips by Martin Fowler
Refactoring Tips by Martin Fowler
 
SAD10 - Refactoring
SAD10 - RefactoringSAD10 - Refactoring
SAD10 - Refactoring
 
Refactoring
RefactoringRefactoring
Refactoring
 
Agile_goa_2013_clean_code_tdd
Agile_goa_2013_clean_code_tddAgile_goa_2013_clean_code_tdd
Agile_goa_2013_clean_code_tdd
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
 
Refactoring PHP
Refactoring PHPRefactoring PHP
Refactoring PHP
 
Software Craftsmanship - 2
Software Craftsmanship - 2Software Craftsmanship - 2
Software Craftsmanship - 2
 
Refactoring: Improve the design of existing code
Refactoring: Improve the design of existing codeRefactoring: Improve the design of existing code
Refactoring: Improve the design of existing code
 
Refactoring
RefactoringRefactoring
Refactoring
 
Tech talks#6: Code Refactoring
Tech talks#6: Code RefactoringTech talks#6: Code Refactoring
Tech talks#6: Code Refactoring
 
Composing method
Composing methodComposing method
Composing method
 
Ddc2011 효과적으로레거시코드다루기
Ddc2011 효과적으로레거시코드다루기Ddc2011 효과적으로레거시코드다루기
Ddc2011 효과적으로레거시코드다루기
 
Refactoring
RefactoringRefactoring
Refactoring
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoring
 
Bad Smell in Codes - Part 1
Bad Smell in Codes - Part 1Bad Smell in Codes - Part 1
Bad Smell in Codes - Part 1
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and Data
 
Refactoring and code smells
Refactoring and code smellsRefactoring and code smells
Refactoring and code smells
 
En story of cakephp2.0
En story of cakephp2.0En story of cakephp2.0
En story of cakephp2.0
 
Naming Standards, Clean Code
Naming Standards, Clean CodeNaming Standards, Clean Code
Naming Standards, Clean Code
 
C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2
 

Recently uploaded

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 

Recently uploaded (20)

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 

Introduction to Refactoring

  • 2. About Me VorleakChy Email (vorleak.chy@gmail.com) Yoolk Inc. (http://www.yoolk.com) Blog (http://vorleakchy.com) Rails Developer .NET Developer
  • 3. What do we talk about Refactoring? What? Why? When? How?
  • 4. Get Agile – Refactoring Practices Tools
  • 5. What is Refactoring? The 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 structure. Fowler, et al., Refactoring, 1999.
  • 6. Before After Easier to understand Clean code Better code Cheaper to modify … More Unreadable code Duplicated code Complex code Hard to modify … More
  • 7. Why do we Refactor? The reality Extremely difficult to get the design “right” the first time Hard to fully understand the problem domain Hard to understand user requirements, even if the user does! Hard to know how the system will evolve in five years Original design is often inadequate System becomes brittle over time, and more difficult to change
  • 8. Why do we Refactor? (Cont.) Helps us to deliver more business values faster Improve code structure and design Easier to maintain and understand Easier to modify More flexibility Easier to add new features Increased re-usability
  • 9. Why do we Refactor?(Cont.) Keep development at speed To make the software easier to understand Write for people, not the compiler Understand unfamiliar code To help us find bugs Refactor while debugging to clarify the code
  • 10. Readability Which code segment is easier to read? Sample 1 if (date.before(Summer_Start) || date.after(Summer_End)) charge = quantity * winterRate + winterServiceCharge; else charge = quantity * summerRate; Sample 2 if (isSummer(date)) charge = summerCharge(quantity); else charge = winterCharge(quantity);
  • 11. When should werefactor? Add new features Fix bugs During code review Only refactor when refactoring. Do not add features during refactoring
  • 12. When Not to Refactor Sometimes you should throw things out and start again Sometimes you are too close to a deadline
  • 13. Costs of Not Refactoring Bad code usually takes more code to do the same thing often because of duplication
  • 14. How do we Refactor? We looks for Code-Smells Things that we suspect are not quite right or will cause us severe pain if we do not fix
  • 15. Common Code Smells Duplicated code Feature Envy Comments Long Method Long parameter list Switch Statements
  • 16. Duplicated code There is obvious duplication Such as copy and paste There are unobvious duplications Such as parallel inheritance hierarchies Similar algorithms Remedy Extract Method Pull Up Field
  • 17. Feature Envy A method that seems more interested in some other classes than the one it is in Remedy Move Method Extract Method
  • 18. Extract Method void printOwning(double amount){ printBanner(); // print details System.Console.WriteLine(string.Format(“name: “, name); System.Console.WriteLine(string.Format(“amount: “, amount); } void printOwning(double amount){ printBanner(); printDetails(amount); } void printDetails(double amount){ System.Console.WriteLine(string.Format(“name: “, name); System.Console.WriteLine(string.Format(“amount: “, amount); }
  • 19. Comments Comments – be suspicious! Comments represent a failure to express an idea in the code Remedy Extract Method Rename Method
  • 20. Long Method Good OO code is easiest to understand and maintain with shorter methods with good names Long methods tend to be harder to read and understand Remedy Extract Method Replace Temp with Query Replace Method with Method Object Decompose Conditional
  • 21. Replace Temp with Query double basePrice = _quanity* _itemPrice; if(basePrice> 1000) { return basePrice * 0.95; } else { return basePrice * 0.98; } if(getBasePrice() > 1000) { return getBasePrice() * 0.95; } else { return getBasePrice() * 0.98; } double getBasePrice() { return _quanitiy * _itemPrice; }
  • 22. Long parameter list Functions should have as few parameters as possible Remedy Replace Parameter with Method Preserve Whole Object Introduce Parameter Object
  • 23. Introduce Parameter Object Customer Customer amountInvoicedIn(Date start, Date end) amountRecivedIn(Date start, Date end) amountOverdueIn(Date start, Date end) amountInvoicedIn(DateRangerange) amountRecivedIn(DateRangerange) amountOverdueIn(DateRangerange)
  • 24. Switch Statements Type cases are evil because they tend to be duplicated many times Remedy Replace Type Code with Subclasses Replace Type Code with State / Strategy Replace Conditional with Polymorphism Replace Parameter with Explicit Methods Introduce Null Object
  • 25. Replace Parameter with Explicit Methods void setValue(String name, int value) { if(name.Equals(“height”)) { _height = value; return; } if(name.Equals(“width”)) { _width = value; return; } } void setHeight(intvalue) { _height = value; } void setWidth(intvalue) { _width = value; }
  • 26. Refactoring Cycle Choose on appropriate Refactoring to apply Apply Refactoring Run ALL Tests (Get GREEN Bar) Reached Desired Structure? No Yes
  • 27. Demo
  • 28. Q & A