The SOLID software methodology
SOLID is an acronym that represents a set of five design principles for writing maintainable and scalable software. These principles were introduced by Robert C. Martin and are widely used in OOP. Let’s take a brief look at each of these SOLID principles.
SRP
A class should have only one reason to change, meaning that it should have only one responsibility.
The following code is an example of a wrong implementation that violates the SRP:
class Report{ public void GenerateReport() { /* ... */ } public void SaveToFile() { /* ... */ } }
This class performs the two responsibilities of generating a report and saving it to a file. Here is the correct implementation:
class Report{ public void GenerateReport() { /* ... */ } } class ReportSaver { public void SaveToFile(Report report) { /* ... */ } }
As you can see, our correct implementation...