Print this page Share

Professional Refactoring in C# & ASP.NET

ISBN: 978-0-470-43452-9
552 pages
April 2009
Professional Refactoring in C# & ASP.NET (047043452X) cover image


Refactoring is an effective way to quickly uncover problematic code and fix it. In this first book to provide a hands-on approach to refactoring in C# and ASP.NET, you'll discover to apply refactoring techniques to manage and modify your code. Plus, you'll learn how to build a prototype application from scratch and discover how to refactor the prototype into a properly designed, enterprise-level application.

With the help of step-by-step directions, you'll gain a better understanding of different code issues and refactoring transformations. Many of these transformations are developed from real-world scenarios that are the result of key business decisions. In addition, you'll find formal definitions of refactoring techniques that you'll be able to refer to while on the job.

This book covers the refactoring techniques that will enable you to become more efficient and productive. You'll be able to use this information to respond to change and improve the design of existing code.

What you will learn from this book

  • How to assemble your own refactoring toolkit
  • Techniques for performing unit testing

  • Tips on refactoring to patterns

  • How to use refactoring to upgrade legacy C# and ASP.NET code

  • Ways to take advantage of the method extraction to eliminate duplicated code

  • How to make code simpler, easier to modify, and more understandable

  • All about object oriented theory and design patterns

  • Methods for using LINQ and other C# 3.0 enhancements

Who this book is for

This book is for C# and ASP.NET developers who want to learn how to effectively manage and modify their code with refactoring tools and features.

Wrox Professional guides are planned and written by working programmers to meet the real-world needs of programmers, developers, and IT professionals. Focused and relevant, they address the issues technology professionals face every day. They provide examples, practical solutions, and expert education in new technologies, all designed to help programmers do a better job.

See More

Table of Contents


Chapter 1: Refactoring: What’s All the Fuss About?

A Quick Refactoring Overview.

The Refactoring Process: A Closer Look.

No Programmer Is an Island.

C# and Refactoring.


Chapter 2: A First Taste of Refactoring.

Sample Application: Calories Calculator.

Refactoring in Action.

Implementing the Persistence Functionality.

Calories Calculator, Refactored Version.


Chapter 3: Assembling a Refactoring Toolkit.

Using an Automated Refactoring Tool.

Unit-Testing Basics: The Testing Harness.

About Version Control.


Chapter 4: Application Prototype: Rent-a-Wheels.

Interviewing the Client.

Taking the Initial Steps in the Rent-a-Wheels Project.

Making the Prototype Work.

Fast and Furious Approach to Programming.


Chapter 5: Basic Hygiene.

Eliminating Dead Code.

Reducing the Scope and Access Level of Unduly Exposed Elements.

Using Explicit Imports.

Removing Unused Assembly References.

Basic Hygiene in the Rent-a-Wheels Application.


Chapter 6: From Problem Domain to Code: Closing the Gap.

Understanding the Problem Domain.

Published and Public Interfaces.


Chapter 7: The Method Extraction Remedy for Duplicated Code.

Encapsulating Code and Hiding the Details.



The Duplicated Code Smell.

Extract Method and Replace Magic Literal Refactoring in the Rent-a-Wheels Application.


Chapter 8: Method Consolidation and Extraction Techniques.

Dealing with Temporary Variables.

Dealing with Long and Nested Conditionals.

Method Reorganization and Rent-a-Wheels.


Chapter 9: Discovering Objects.

A Brief Object-Oriented Programming Overview.

Designing Classes.

Discovering Hidden Classes.


Chapter 10: Advanced Object-Oriented Concepts and Related Refactorings.

Inheritance, Polymorphism, and Genericity.

Inheritance Abuse and Refactoring Solutions.

Making Use of Generics.


Chapter 11: Code Organization on a Large Scale.



C# Project File Structure Organization.

Namespace Organization and Windows Forms Inheritance in Rent-a-Wheels.


Chapter 12: Refactoring to Patterns.

Design Patterns: What’s All the Fuss About?

Example Design Pattern: Abstract Factory.

Dependency Injection Pattern.

Refactoring to Patterns and the Rent-a-Wheels Application.


Chapter 13: LINQ and Other C# 3.0 Enhancements.

Type Inference for Local Variables.


Chapter 14: A Short History of the Web for Developers and ASP.NET Tooling.

Refactor! for ASP.NET.

HTML History and Its Legacy.

Catching Up with theWeb.


Chapter 15: Refactoring ASP.NET Applications.

Refactoring HTML.

Refactoring ASP.NET Code.

Rent-a-Wheels and ASP.NET Refactorings.


Appendix A: Rent-a-Wheels Prototype Internals and Intricacies.

Hand Over Button Click Event-Handling Code.

Display Button Click Event-Handling Routine.


Appendix B: Unleash Refactor! for ASP.NET.


See More

Author Information

Danijel Arsenovski is an author, software architect, and agile coach. Currently, he works as Product and Solutions Architect at Excelsys S.A., designing web 2.0 banking solutions for numerous clients in the region. He started experimenting with refactoring while overhauling a huge banking system, and he hasn’t lost interest in refactoring ever since. He is known for evangelizing about refactoring on the .NET platform. Arsenovski is a contributing author for Visual Studio Magazine, .NET Developers Journal, and Visual Systems Journal. He holds the Microsoft Certified Solution Developer (MCSD) certification, and was named Microsoft MVP in 2005. You can reach him at danijel.arsenovski@empoweragile.com, and feel free to drop by at his blog at http://blog.refactoring.net.
See More


Download TitleSizeDownload
All sample code from book 5.95 MB Click to Download
Chapter 2 1.04 MB Click to Download
Chapter 3 350.02 KB Click to Download
Chapter 4 146.04 KB Click to Download
Chapter 5 141.93 KB Click to Download
Chapter 6 147.09 KB Click to Download
Chapter 7 263.28 KB Click to Download
Chapter 8 168.88 KB Click to Download
Chapter 9 320.83 KB Click to Download
Chapter 10 400.57 KB Click to Download
Chapter 11 518.57 KB Click to Download
Chapter 12 501.21 KB Click to Download
Chapter 13 1.01 MB Click to Download
Chapter 15 1.01 MB Click to Download
See More


Do you think you've discovered an error in this book? Please check the list of errata below to see if we've already addressed the error. If not, please submit the error via our Errata Form. We will attempt to verify your error; if you're right, we will post a correction below.

ChapterPageDetailsDatePrint Run
10 Error in Code
The last line in "More Readable Code" column in the table on the page 10 should read as follow:

39 Error in Code
There is an faulty space between myPatient. and IdealBodyWeightMale();

It should be:

2, Figure 6-5 62 Error in Text


should be:


301 Error in Code
if (History.Total > 3000)

Should be:

if (History.Total > 3000 & History.Total < 10000)
337 Error in Text
on page 337, on line 3 instead of:
should say:
See More

Related Titles

Back to Top