Humble Newbie
Humble Newbie

Reputation: 107

need advice on understanding SRP (examples provided)

  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.

Upvotes: 0

Views: 41

Answers (0)

Related Questions