SUMMARY

Developers never write perfect code the first time. In practice, trying to write the “perfect method” the first time through is a mistake. Strive to get your application working and your tests passing. With a suite of unit tests that validate your code, you can refactor fearlessly.

Refactoring is to code what editing is to a book or article. Be merciless with your code. Refactor it to increase maintainability. Refactor to make your code more testable. Refactor it to ensure that it obeys the three tenets of OOP: encapsulation, inheritance, and polymorphism. Refactor to make sure you are abiding by the SOLID Principles: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion. All these things not only increase the quality of your code, but also sharpen your skills as a developer and make you a better practitioner of TDD.

Code smells are antipatterns in code. Learn to identify them. Familiarize yourself with refactoring patterns to be able to quickly and easily deal with these code smells. Be sure to use your unit tests to verify that you have not broken the code's business functionality with your refactoring.

Finally, continue to study the tenets of OOP and the SOLID Principles. These concepts are not destinations; they are journeys. You'll always have opportunities to improve how you write code. Don't stop learning.

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.