Implementation of the Dependency Inversion Principle
Explore how to implement the dependency inversion principle to enhance software modularity and testability. Understand how decoupling dependencies allows writing unit tests effectively and increases design flexibility by preventing tight coupling in C# applications.
We'll cover the following...
We have the following codebase, which adheres to the single responsibility principle, open-closed principle, Liskov substitution principle, and interface segregation principle:
Note: Run the following code. The program will ask for the file to convert. Enter
sample.txtas the name of the file. When the program stops execution, press any key to return to the terminal. Now, enter thecat sample.htmlcommand to see the content after conversion.
This is the first paragraph. It has *bold text*. This is the second paragraph. It has **italic text**. This is the third paragraph. It has ~~text with strike-through~~.
Having all the logic inside the Program.cs file is probably not the best way of doing things. It’s meant to be purely an entry point for the application. Because it’s a console application, providing input from the console and output to it is also acceptable. However, having it to coordinate text conversion logic between separate classes is probably not something we want to do.
So, we’ve moved our logic into a separate ...