Implementing the Open-Closed Principle
Understand the importance of the open-closed principle with an example.
We'll cover the following...
In the following playground, we have an application that reads the text from any text file and converts it into HTML by enclosing every paragraph in the p
tags:
Note: Run the following code. The program will ask for the file to convert. Enter
sample.txt
as the name of the file. When the program stops execution, press any key to return to the terminal. Now, enter thecat sample.html
command 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~~.
Initial implementation of the single responsibility principle
This application has the following files:
- The
FileProcessor.cs
file: It reads the input file and saves the output into an HTML file. - The
TextProcessor.cs
file: It processes the text from the input file. - The
Program.cs
file: It serves as the entry point into the