2.6. How to Cope with Design Changes
Over time, all designs change. The system that you spent countless hours in design meetings for will change. Users will add requirements that do not fit into your original vision of how the application would work and the initial architecture that was designed. Other times you realize that there is a much simpler way to implement a section of code than you had originally thought, and you change the code to reflect this.
This is the process of refactoring. Refactoring is the process of improving code, without changing the result the code produces. Improvements include readability, testability, performance, and the general maintainability of your code base.
In Martin Fowler's book Refactoring: Improving the Design of Existing Code, he describes the various refactorings that can perform on code bases, when they should be performed, and the advantages they bring. In the refactoring book, Flower introduces the refactoring patterns and gives each type of refactoring a name to allow the concept to be described and shared with other people.
Examples of common refactoring include Extract method, move to class, and pull-up methods. In the next few examples you will apply common refactorings:
private string SetSalesManagers(string phoneNumber) { int areaCode = int.Parse(phoneNumber.Substring(0, 3)); string region = string.Empty; switch (areaCode)
{ case 248: region = "Central"; break; case 818: region = "West"; break; case 201: region = "East"; break; ...
Get Testing ASP.NET Web Applications now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.