Articles related to Refactoring

Refactoring to Composite Pattern

I often come across functions that do multiple things. Many times such functions have a common pattern where multiple sections within the function use the same parameters for calculations. The results from these different code sections within the function are…

Introduce Tests when Fixing Bugs

When creating a subscription for a client, the calculated number of months was off by one at times - This was a bug reported from production application that I was currently working on. Though, not a blocker, it was creating enough issues for the end users…

Refactoring to Improve Readability - Separating Business Language and Programming Language Semantics

Often we write ourselves or come across code that has both business language and the programming language semantics mixed together. This makes it very hard to reason about the code and also fix any issues. It's easier to read code that is composed of different…

Refactoring to Improve Testability: Extracting Dependencies

In the earlier post, Removing Unnecessary Dependencies , we saw how having an unnecessary dependency hinders testability. In this post we will see just the opposite of that - extracting functionality out of a class and creating another class to separate…

Refactoring Test Code: Removing Constructor Dependency

In the earlier post, Removing Unnecessary Dependencies , we saw how having an unnecessary dependency hinders testability. In this post we will see how the test code changed by the refactoring we did for removing the unnecessary dependency and explore ways to…

Refactoring to Improve Testability: Removing Unnecessary Dependencies

Nowadays I am trying to stick to TDD (with the test first approach) and have found it to be of great help. One of the biggest reward doing TDD is that it helps me to stay in the flow and regain speed faster after a distraction. This post explains how to…

Replace ‘Introduce Local Extension’ With ‘Extension Methods’

Introduce Foreign Method( IFM ) and Introduce Local Extension( ILE ) are two refactoring techniques that comes handy when you need to add functionality to an exisiting class,source code of which is beyond your control. IFM is used when its just one or two…

TDD and Refactoring

Over the days I have been reading on Test Driven Development(TDD) and it seems really interesting methodology to go with as per development is concerned. Basic of TDD is that the development process relies on 'tests', that are written prior to code. Sounds…