The file system stores school reports. There are personal reports - personal for each school ( School class). And there are general reports - reports that contain general information / statistics on schools in the region.

Metadata (information about reports) is stored in the ReportMeta class and they are the same for both personal and general reports:

 public class ReportMeta { public string Name { get; set; } public DateTime PublishDate { get; set; } public string OnlineLink { get; set; } //... } 

Algorithms for receiving ReportMeta for personal and general reports are different . Moreover, the ReportMeta receipt ReportMeta for personal reports is constant, but the code for general reports may change in the future, since The storage structure of these (general reports) will be different and it is planned to add other types of reports. So I made the disconnect:

 public interface IReportMeta { IEnumerable<ReportMeta> GetReportMetas(); } public class PrivateReportMeta : IReportMeta { private School school; public PrivateReportMeta(School school) { this.school = school; } public IEnumerable<ReportMeta> GetReportMetas() { //… return new List<ReportMeta>(); } } public class PublicReportMeta : IReportMeta { public IEnumerable<ReportMeta> GetReportMetas() { //... return new List<ReportMeta>(); } } 

Client code needs to get ReportMeta lists in a common heap and therefore the following is assumed:

 static void Main(string[] args) { School currentSchool = new School(); IReportMeta privateReportMetas = new PrivateReportMeta(currentSchool); IReportMeta publicReportMetas = new PublicReportMeta(); var allReportMetas = privateReportMetas.GetReportMetas().Union(publicReportMetas.GetReportMetas()); //... } 

Question

  1. Does the code follow the SOLID principles?
  2. Is there a gross violation in the design of the application?

I would be grateful for the proposal of another architecture.

    1 answer 1

    1. The principles of SOLID are just recommendations. In my opinion, this is all you have in order.
    2. First, Union is not doing what you want, use Concat. Secondly, to get rid of a large number of new ...ReportMeta , you can use the Factory pattern. This is true if you have many types of reports. For two, I think, and so normal.
    • You can apply the Factory pattern . And what about the pattern in particular - Abstract Factory or Factory Method ? - Adam
    • @adamshakhabov Either the usual Factory , or Factory Method . You can read about the difference here , though in C ++ - RusArt