Lesson 1
What Will be Covered in This Course Path
Introduction to the Course Path

Welcome to the course path for Refactoring Techniques in C#. Before we begin the first course, let's discuss the themes of this course path, what we will cover, and how we will approach our practice sessions.

Our journey will focus on equipping us with the skills to confidently modify existing codebases while minimizing the risk of introducing bugs. By the end of this course, we'll be well-versed in various strategies to make our code more testable and reliable.

Challenges in Established Codebases

Working with established codebases often presents unique challenges. These include dealing with tightly coupled components, a lack of documentation, and the fear of breaking existing functionality when making changes. Without the use of proper tools and techniques, even minor modifications can lead to unexpected issues.

Tools Used Within This Course Path

As we progress through the path, we will be using a few dotnet libraries to help us along the way. While they are going to be used extensively within this course, keep in mind that they are just some of the options available out there, and that other projects might use different tools. The point is to understand why we use them, not the particular tool.

We'll be using Xunit, a popular testing framework, to write and run tests effectively. Refactoring will be a significant focus, as it helps increase testability by creating interfaces and breaking down dependencies. We'll also explore the use of Moq, a mocking library, to isolate and test components without external dependencies.

Topics Covered Within This Course Path

All courses will work with an existing codebase. This means that we will always start with some existing state, and will use it to demonstrate a concept, technique, or strategy.

The first course will revolve around writing tests and enhancing testability. The second course will go deeper into breaking dependencies, and how to use dependency injection and inversion of control in a practical way. The third course will cover how to discover and use seams to enable testability and expand capabilities, while the last course will talk about sprout and wrap techniques for refactoring.

Practical Application with an Order Processor

To make these concepts tangible, we'll use an order processor as our central example throughout the vast majority of our lesson and practice sessions. This practical application will serve as a playground for applying the techniques learned. By working through real-world scenarios, we'll gain a deeper understanding of how to implement these strategies in our own projects. This is one example of how the order processor might look like:

C#
1public class OrderProcessor 2{ 3 public bool ProcessOrder(Order order) 4 { 5 decimal totalAmount = 0; 6 foreach (var item in order.Items) 7 { 8 decimal itemPrice = item.Price * item.Quantity; 9 totalAmount += itemPrice; 10 } 11 12 order.OrderTotal = totalAmount; 13 return true; 14 } 15} 16 17public class Order 18{ 19 public List<OrderItem> Items { get; set; } 20 public decimal OrderTotal { get; set; } 21} 22 23public class OrderItem 24{ 25 public decimal Price { get; set; } 26 public int Quantity { get; set; } 27}

Depending on the topic at hand, the order processor will be contrived to best demonstrate said topic, hopefully helping us grasp the concepts discussed.

Summary

Now that we have covered the basics, let's look at an intro practice session aimed at getting us familiar with our practice playground. Let's move on to see the first version of the order processor.

Enjoy this lesson? Now it's time to practice with Cosmo!
Practice is how you turn knowledge into actual skills.