0
  1. This is a method that provides a list of .csv files from inside the project folder
    public static List<string> GetListOfTables()
     {
         var tables = new List<string>();
    
         do
         {
             tables = Directory
                     .GetFiles(".", "*.csv")
                     .Select(file => Path.GetFileName(file))
                     .ToList();
    
             if (tables.Count == 0)
             {
                 Output.Invoke("\nNo .csv files are found, " +
                 "please put a table csv file in the program folder " +
                 "and press <Enter> to continue");
    
                 while (Console.ReadKey(true).Key != ConsoleKey.Enter) { }
             }
         }
         while (tables.Count == 0);
    
         return tables;
     }

Here, besides getting files names, I added a built-in validation for empty folder. Is this inline the SRP or the method is overloaded and it is better to create a separate validation method and then link it inside the master method? I believe since there is no reason to change the validation logic in the future, I can keep it as it is not breaking SRP (?).

  1. There is a class with the main purpose to parse .csv file into a list of objects.
static class CsvParser
        {
            public static List<string> GetListOfTables() { }

            // The user is making a choice from the list of tables 
            // via a method outside of this class. 
   
            public static List<List<object>> GetTable(string tableName) { }
        }

Since the main purpose of this class is to actually parse, isn't a method that gather list of files breaks the SRP? In the same time, dividing already small utility class into two classes feels like overkill here and the logic of getting the list of files unlikely to be changed (?).

Even though I'm a complete beginner yet, I'd like to get a straight vision on this sooner than later and don't run into a bad habit from the beginning.

Humble Newbie
  • 98
  • 1
  • 11
  • 1
    SRP doesn't necessarily means doing only a single task but rather single responsibility. In this case to me it looks fine to have the responsibility as fetching the file names and validating them but I would separate the validation method for the purpose of Re-Use. – Rahul Mar 14 '23 at 11:53
  • I’m voting to close this question because there is no actual problem to be solved, and it is subjective in a non-constructive way. – Scott Solmer Mar 14 '23 at 12:02
  • I do apologies for the inconvenience, it can be closed then. I tried to delete it by now but changed my mind - perhaps another newbie came here with the same question and find all the info @Rahul Thank you! – Humble Newbie Mar 14 '23 at 12:04

0 Answers0