SlideShare a Scribd company logo
1 of 37
Effective Refactoring
Arnon Axelrod
Copyright © SELA Software & Education Labs, Ltd. | 14-18 Baruch Hirsch St., Bnei Brak 51202, Israel | www.selagroup.com
About me
Arnon Axelrod
https://blogs.microsoft.co.il/blogs/arnona
ArnonAxelrod
What is Refactoring?
restructuring existing
computer code, without
changing its external
behavior
Clean Code
Measuring Clean Code
Clean Code
• Readability
– Naming
– Formatting
• Method length
• Number of parameters
• Modularity and Reusability
– Law of Demeter
– Avoid static and Singletons
• Exception Handling
Law of Demeter
Method f in class C should only call methods of:
C
An object created by f
An object passed as an argument to f
An object held by an instance variable of C
Counter example:
string outputDir =
ctxt.getOptions().getScratchDir().getAbsolutePath();
The SOLID principles
• Single Responsibility
• Open/Close
• Liskov Substitution
• Interface Segregation
• Dependency Inversion
4 Rules of Simple Design / Kent Beck
• Passes all the tests
• Reveals the intent
• No duplication (DRY)
• Fewest elements (YAGNI)
(order matters)
Poka Yoke
Poka Yoke - examples
• private/public
• readonly fields and get-only properties
• Use classes instead of strings and integers
• Use most specific interfaces
– E.g. IReadOnlyCollection<T> instead of List<T>
Strong Typing
With strong typing:
With primitive types:
Refactoring / Martin Fowler
Refactoring – Best Practices
• Small Steps
• Test Often
• Write missing unit-tests
• Pair-programming
• Add before remove
• Use TODO and [Obsolete] midway
Add Before Remove
public class SomeClass
{
public SomeClass()
{
//...
}
public void Foo(int someParam)
{
// use someParam...
}
}
Initial state
Add Before Remove
public class SomeClass
{
private int _someParam;
public SomeClass(int someParam)
{
//...
_someParam = someParam;
}
public void Foo()
{
// use _someParam...
}
}
Final (desired)
state
Add Before Remove
public class SomeClass
{
public SomeClass()
{
//...
}
public void Foo(int someParam)
{
// use someParam...
}
}
Initial state
Add Before Remove
public class SomeClass
{
public SomeClass()
{
//...
}
private int _someParam;
public SomeClass(int someParam) : this()
{
_someParam = someParam;
}
public void Foo(int someParam)
{
//use someParam...
}
}
Step1 – Add
constructor
overload
Add Before Remove
public class SomeClass
{
private int _someParam;
public SomeClass(int someParam)
{
//...
_someParam = someParam;
}
public void Foo(int someParam)
{
//use someParam...
}
}
Step2 – Remove old
constructor overload
Add Before Remove
public class SomeClass
{
private int _someParam;
public SomeClass(int someParam)
{
//...
_someParam = someParam;
}
public void Foo(int someParam)
{
//use someParam...
}
public void Foo()
{
Foo(_someParam);
}
}
Step3 – Add
new overload
of Foo
Add Before Remove
public class SomeClass
{
private int _someParam;
public SomeClass(int someParam)
{
//...
_someParam = someParam;
}
public void Foo()
{
//use _someParam...
}
}
Step4 (final) –
Remove old
overload of Foo
Refactoring with Resharper
Refactoring with Resharper
Resharper Refactorings
• Rename
• Extract Method/Inline method
• Change Signature
• Introduce variable/Inline variable
• Introduce field/Inline field
• Introduce parameter/Inline parameter
• Transform parameters (to new class)
• Convert Property to Method(s)/Convert
• Convert Extension Method to Static/Convert Static to Extension Method
• Convert Interface to Abstract Class/Convert Abstract Class to Interface
• Replace Constructor with Factory method
• Move Instance Method, Move to Another Type
• Safe Delete
• And more…
Inline Method
Change Signature
Introduce Field
Extract Super Class
Pull Members Up
Extract Interface
Encapsulate Field
Convert Property to Method(s)
Move to Another Type
Code Analysis
Summary
• Clean code is essential for productivity
and quality
• Refactoring is essential to keep clean
code
• It’s important to learn and practice
Clean Code and Refactoring
• Mastering the tools will make you
hyper-productive!
Questions

More Related Content

What's hot

Operator Overloading
Operator OverloadingOperator Overloading
Operator OverloadingNilesh Dalvi
 
Presentation on overloading
Presentation on overloading Presentation on overloading
Presentation on overloading Charndeep Sekhon
 
Lombok Features
Lombok FeaturesLombok Features
Lombok Features文峰 眭
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++gourav kottawar
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++Nilesh Dalvi
 
pointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cpppointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cppgourav kottawar
 
Operator overloading and type conversions
Operator overloading and type conversionsOperator overloading and type conversions
Operator overloading and type conversionsAmogh Kalyanshetti
 
Wait for your fortune without Blocking!
Wait for your fortune without Blocking!Wait for your fortune without Blocking!
Wait for your fortune without Blocking!Roman Elizarov
 
Operator Overloading & Type Conversions
Operator Overloading & Type ConversionsOperator Overloading & Type Conversions
Operator Overloading & Type ConversionsRokonuzzaman Rony
 
Lec 26.27-operator overloading
Lec 26.27-operator overloadingLec 26.27-operator overloading
Lec 26.27-operator overloadingPrincess Sam
 
Writing code that writes code - Nguyen Luong
Writing code that writes code - Nguyen LuongWriting code that writes code - Nguyen Luong
Writing code that writes code - Nguyen LuongVu Huy
 
OOP with Java - Abstract Classes and Interfaces
OOP with Java - Abstract Classes and InterfacesOOP with Java - Abstract Classes and Interfaces
OOP with Java - Abstract Classes and InterfacesHitesh-Java
 
Effective Java - Generics
Effective Java - GenericsEffective Java - Generics
Effective Java - GenericsRoshan Deniyage
 
C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and OperatorsSunil OS
 
A Brief Conceptual Introduction to Functional Java 8 and its API
A Brief Conceptual Introduction to Functional Java 8 and its APIA Brief Conceptual Introduction to Functional Java 8 and its API
A Brief Conceptual Introduction to Functional Java 8 and its APIJörn Guy Süß JGS
 

What's hot (19)

Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Presentation on overloading
Presentation on overloading Presentation on overloading
Presentation on overloading
 
Lombok Features
Lombok FeaturesLombok Features
Lombok Features
 
Core java day4
Core java day4Core java day4
Core java day4
 
Overloading
OverloadingOverloading
Overloading
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
pointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cpppointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cpp
 
Operator overloading and type conversions
Operator overloading and type conversionsOperator overloading and type conversions
Operator overloading and type conversions
 
Wait for your fortune without Blocking!
Wait for your fortune without Blocking!Wait for your fortune without Blocking!
Wait for your fortune without Blocking!
 
Operator Overloading & Type Conversions
Operator Overloading & Type ConversionsOperator Overloading & Type Conversions
Operator Overloading & Type Conversions
 
Lec 26.27-operator overloading
Lec 26.27-operator overloadingLec 26.27-operator overloading
Lec 26.27-operator overloading
 
Writing code that writes code - Nguyen Luong
Writing code that writes code - Nguyen LuongWriting code that writes code - Nguyen Luong
Writing code that writes code - Nguyen Luong
 
Compile time polymorphism
Compile time polymorphismCompile time polymorphism
Compile time polymorphism
 
OOP with Java - Abstract Classes and Interfaces
OOP with Java - Abstract Classes and InterfacesOOP with Java - Abstract Classes and Interfaces
OOP with Java - Abstract Classes and Interfaces
 
expression in cpp
expression in cppexpression in cpp
expression in cpp
 
Effective Java - Generics
Effective Java - GenericsEffective Java - Generics
Effective Java - Generics
 
C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and Operators
 
A Brief Conceptual Introduction to Functional Java 8 and its API
A Brief Conceptual Introduction to Functional Java 8 and its APIA Brief Conceptual Introduction to Functional Java 8 and its API
A Brief Conceptual Introduction to Functional Java 8 and its API
 

Similar to Effective refactoring

Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014FalafelSoftware
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingSteven Smith
 
TechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
TechkTalk #12 Grokking: Writing code that writes code – Nguyen LuongTechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
TechkTalk #12 Grokking: Writing code that writes code – Nguyen LuongGrokking VN
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and DestructorsKeyur Vadodariya
 
Csharp4 objects and_types
Csharp4 objects and_typesCsharp4 objects and_types
Csharp4 objects and_typesAbed Bukhari
 
Handling Exceptions In C &amp; C++ [Part B] Ver 2
Handling Exceptions In C &amp; C++ [Part B] Ver 2Handling Exceptions In C &amp; C++ [Part B] Ver 2
Handling Exceptions In C &amp; C++ [Part B] Ver 2ppd1961
 
SenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
SenchaCon 2016: Modernizing the Ext JS Class System - Don GriffinSenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
SenchaCon 2016: Modernizing the Ext JS Class System - Don GriffinSencha
 
03 classes interfaces_principlesofoop
03 classes interfaces_principlesofoop03 classes interfaces_principlesofoop
03 classes interfaces_principlesofoopVladislav Hadzhiyski
 
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testabilityPHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testabilityGiorgio Sironi
 
Java script Techniques Part I
Java script Techniques Part IJava script Techniques Part I
Java script Techniques Part ILuis Atencio
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)rashmita_mishra
 
CSharp presentation and software developement
CSharp presentation and software developementCSharp presentation and software developement
CSharp presentation and software developementfrwebhelp
 
C questions
C questionsC questions
C questionsparm112
 
Object-Oriented Programming with C#
Object-Oriented Programming with C#Object-Oriented Programming with C#
Object-Oriented Programming with C#Svetlin Nakov
 
OOP with Java - Part 3
OOP with Java - Part 3OOP with Java - Part 3
OOP with Java - Part 3RatnaJava
 
TWINS: OOP and FP - Warburton
TWINS: OOP and FP - WarburtonTWINS: OOP and FP - Warburton
TWINS: OOP and FP - WarburtonCodemotion
 
00-intro-to-classes.pdf
00-intro-to-classes.pdf00-intro-to-classes.pdf
00-intro-to-classes.pdfTamiratDejene1
 

Similar to Effective refactoring (20)

Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
 
TechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
TechkTalk #12 Grokking: Writing code that writes code – Nguyen LuongTechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
TechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
C++ idioms.pptx
C++ idioms.pptxC++ idioms.pptx
C++ idioms.pptx
 
Csharp4 objects and_types
Csharp4 objects and_typesCsharp4 objects and_types
Csharp4 objects and_types
 
Koin Quickstart
Koin QuickstartKoin Quickstart
Koin Quickstart
 
C++ theory
C++ theoryC++ theory
C++ theory
 
Handling Exceptions In C &amp; C++ [Part B] Ver 2
Handling Exceptions In C &amp; C++ [Part B] Ver 2Handling Exceptions In C &amp; C++ [Part B] Ver 2
Handling Exceptions In C &amp; C++ [Part B] Ver 2
 
SenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
SenchaCon 2016: Modernizing the Ext JS Class System - Don GriffinSenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
SenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
 
03 classes interfaces_principlesofoop
03 classes interfaces_principlesofoop03 classes interfaces_principlesofoop
03 classes interfaces_principlesofoop
 
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testabilityPHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
 
Java script Techniques Part I
Java script Techniques Part IJava script Techniques Part I
Java script Techniques Part I
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
 
CSharp presentation and software developement
CSharp presentation and software developementCSharp presentation and software developement
CSharp presentation and software developement
 
C questions
C questionsC questions
C questions
 
Object-Oriented Programming with C#
Object-Oriented Programming with C#Object-Oriented Programming with C#
Object-Oriented Programming with C#
 
OOP with Java - Part 3
OOP with Java - Part 3OOP with Java - Part 3
OOP with Java - Part 3
 
TWINS: OOP and FP - Warburton
TWINS: OOP and FP - WarburtonTWINS: OOP and FP - Warburton
TWINS: OOP and FP - Warburton
 
00-intro-to-classes.pdf
00-intro-to-classes.pdf00-intro-to-classes.pdf
00-intro-to-classes.pdf
 

More from Arnon Axelrod

Defect free development - QS Tag2019
Defect free development - QS Tag2019Defect free development - QS Tag2019
Defect free development - QS Tag2019Arnon Axelrod
 
Test Automation Maturity Model (Israel Test Automation meetup 12/11/2018)
Test Automation Maturity Model (Israel Test Automation meetup 12/11/2018)Test Automation Maturity Model (Israel Test Automation meetup 12/11/2018)
Test Automation Maturity Model (Israel Test Automation meetup 12/11/2018)Arnon Axelrod
 
Test automation and architecture
Test automation and architectureTest automation and architecture
Test automation and architectureArnon Axelrod
 
Unit Testing, TDD and ATDD
Unit Testing, TDD and ATDDUnit Testing, TDD and ATDD
Unit Testing, TDD and ATDDArnon Axelrod
 
Software quality - no more bugs!
Software quality - no more bugs!Software quality - no more bugs!
Software quality - no more bugs!Arnon Axelrod
 
Automation at Philips Healthcare
Automation at Philips HealthcareAutomation at Philips Healthcare
Automation at Philips HealthcareArnon Axelrod
 

More from Arnon Axelrod (11)

Defect free development - QS Tag2019
Defect free development - QS Tag2019Defect free development - QS Tag2019
Defect free development - QS Tag2019
 
ATDD open house
ATDD open houseATDD open house
ATDD open house
 
Test Automation Maturity Model (Israel Test Automation meetup 12/11/2018)
Test Automation Maturity Model (Israel Test Automation meetup 12/11/2018)Test Automation Maturity Model (Israel Test Automation meetup 12/11/2018)
Test Automation Maturity Model (Israel Test Automation meetup 12/11/2018)
 
Competitive code
Competitive codeCompetitive code
Competitive code
 
Beyond pageobjects
Beyond pageobjectsBeyond pageobjects
Beyond pageobjects
 
Test automation and architecture
Test automation and architectureTest automation and architecture
Test automation and architecture
 
Unit Testing, TDD and ATDD
Unit Testing, TDD and ATDDUnit Testing, TDD and ATDD
Unit Testing, TDD and ATDD
 
Software quality - no more bugs!
Software quality - no more bugs!Software quality - no more bugs!
Software quality - no more bugs!
 
C# in depth
C# in depthC# in depth
C# in depth
 
ATDD with SpecFlow
ATDD with SpecFlowATDD with SpecFlow
ATDD with SpecFlow
 
Automation at Philips Healthcare
Automation at Philips HealthcareAutomation at Philips Healthcare
Automation at Philips Healthcare
 

Recently uploaded

Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 

Recently uploaded (20)

Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 

Effective refactoring

  • 1. Effective Refactoring Arnon Axelrod Copyright © SELA Software & Education Labs, Ltd. | 14-18 Baruch Hirsch St., Bnei Brak 51202, Israel | www.selagroup.com
  • 3. What is Refactoring? restructuring existing computer code, without changing its external behavior
  • 6. Clean Code • Readability – Naming – Formatting • Method length • Number of parameters • Modularity and Reusability – Law of Demeter – Avoid static and Singletons • Exception Handling
  • 7. Law of Demeter Method f in class C should only call methods of: C An object created by f An object passed as an argument to f An object held by an instance variable of C Counter example: string outputDir = ctxt.getOptions().getScratchDir().getAbsolutePath();
  • 8. The SOLID principles • Single Responsibility • Open/Close • Liskov Substitution • Interface Segregation • Dependency Inversion
  • 9. 4 Rules of Simple Design / Kent Beck • Passes all the tests • Reveals the intent • No duplication (DRY) • Fewest elements (YAGNI) (order matters)
  • 11. Poka Yoke - examples • private/public • readonly fields and get-only properties • Use classes instead of strings and integers • Use most specific interfaces – E.g. IReadOnlyCollection<T> instead of List<T>
  • 12. Strong Typing With strong typing: With primitive types:
  • 14. Refactoring – Best Practices • Small Steps • Test Often • Write missing unit-tests • Pair-programming • Add before remove • Use TODO and [Obsolete] midway
  • 15. Add Before Remove public class SomeClass { public SomeClass() { //... } public void Foo(int someParam) { // use someParam... } } Initial state
  • 16. Add Before Remove public class SomeClass { private int _someParam; public SomeClass(int someParam) { //... _someParam = someParam; } public void Foo() { // use _someParam... } } Final (desired) state
  • 17. Add Before Remove public class SomeClass { public SomeClass() { //... } public void Foo(int someParam) { // use someParam... } } Initial state
  • 18. Add Before Remove public class SomeClass { public SomeClass() { //... } private int _someParam; public SomeClass(int someParam) : this() { _someParam = someParam; } public void Foo(int someParam) { //use someParam... } } Step1 – Add constructor overload
  • 19. Add Before Remove public class SomeClass { private int _someParam; public SomeClass(int someParam) { //... _someParam = someParam; } public void Foo(int someParam) { //use someParam... } } Step2 – Remove old constructor overload
  • 20. Add Before Remove public class SomeClass { private int _someParam; public SomeClass(int someParam) { //... _someParam = someParam; } public void Foo(int someParam) { //use someParam... } public void Foo() { Foo(_someParam); } } Step3 – Add new overload of Foo
  • 21. Add Before Remove public class SomeClass { private int _someParam; public SomeClass(int someParam) { //... _someParam = someParam; } public void Foo() { //use _someParam... } } Step4 (final) – Remove old overload of Foo
  • 24. Resharper Refactorings • Rename • Extract Method/Inline method • Change Signature • Introduce variable/Inline variable • Introduce field/Inline field • Introduce parameter/Inline parameter • Transform parameters (to new class) • Convert Property to Method(s)/Convert • Convert Extension Method to Static/Convert Static to Extension Method • Convert Interface to Abstract Class/Convert Abstract Class to Interface • Replace Constructor with Factory method • Move Instance Method, Move to Another Type • Safe Delete • And more…
  • 32. Convert Property to Method(s)
  • 35.
  • 36. Summary • Clean code is essential for productivity and quality • Refactoring is essential to keep clean code • It’s important to learn and practice Clean Code and Refactoring • Mastering the tools will make you hyper-productive!

Editor's Notes

  1. באתי מהכיוון של Clean code ו-Unit tests לתחום הבדיקות האוטומטיות. היום אני רוצה לחזור כי לדעתי שם נמצאות הבעיות האמיתיות...
  2. The goal: to improve maintainability It’s not: A complete rewrite Bug fixing Changing a technology (to some extent) Behavior is contextual What are the boundaries of the refactored system? Is “performance” considered behavior Is CPU and memory consumption behavior? Is Reflection should be preserved? Exceptions (backward compatibility) Does the bits should be preserved…? We should know our presumptions
  3. But really: Amount of time spent on debugging and understanding of code Makes it easier to prove correctness and avoid bugs Makes it easy and safe to make changes
  4. רשימה חלקית, ממש על קצה המזלג, של הכללים שנכללים תחת הקטגוריה של Clean code
  5. Many of these principles rely on Polymorphism which is based on the concept of callback functions. This is a concept that developers must master
  6. בא לידי ביטוי בארכיטקטורה, בקוד ובתהליכי העבודה (למשל strongly typed)
  7. להחליף תמונה TDD provides a safety net Caution: If tests are bad, refactoring can be more difficult than without! On the other hand, TDD drives for good tests Small steps, climbers rule
  8. להחליף תמונה TDD provides a safety net Caution: If tests are bad, refactoring can be more difficult than without! On the other hand, TDD drives for good tests Small steps, climbers rule
  9. להחליף תמונה TDD provides a safety net Caution: If tests are bad, refactoring can be more difficult than without! On the other hand, TDD drives for good tests Small steps, climbers rule
  10. להחליף תמונה TDD provides a safety net Caution: If tests are bad, refactoring can be more difficult than without! On the other hand, TDD drives for good tests Small steps, climbers rule
  11. להחליף תמונה TDD provides a safety net Caution: If tests are bad, refactoring can be more difficult than without! On the other hand, TDD drives for good tests Small steps, climbers rule
  12. להחליף תמונה TDD provides a safety net Caution: If tests are bad, refactoring can be more difficult than without! On the other hand, TDD drives for good tests Small steps, climbers rule
  13. Value Tracking Call Tracking Type Hierarchy