3

A Quick Review of Refactoring

WHAT'S IN THIS CHAPTER?

  • Why Refactoring application code is important
  • How Clean Code principals such as OOP and SOLID help you build robust applications
  • How to identify and fix some of the most common design and coding mistakes in application development

No code is perfect. For developers, accepting this fact is very freeing. There will always be something you could have done better, although maybe you don't realize it at the time. Looking at code you've written in previous years, you may sometimes find small, subtle things you would like to change to make the code faster, more aligned with the business, or simply easier to maintain. Other times you may say, “If only I knew then what I know now, I would have done this completely different.”

Refactoring is the act of changing the internal implementation of a class or method with the aim of making the code more readable and maintainable. Refactoring also reduces the code's overall complexity without changing the external behavior of the class or method. These alterations can be as simple as changing the name of a method or variable to moving methods from one class to another or even splitting large classes into several smaller ones. Refactoring allows you to continuously change and improve your code.

This chapter explains why refactoring your code is important. It reviews object-oriented programming and the SOLID Principles. It also shows you some common coding and design problems, colloquially ...

Get Professional Test-Driven Development with C#: Developing Real World Applications with TDD 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.