Sobes.tech
Junior — Senior

Refactoring code fragment according to SOLID principles

livecode

Task condition

It is necessary to improve this example by eliminating SOLID violations and making it more maintainable and readable. Apply appropriate structural changes to the class and its methods.

public class BirthdayTemplateProcessor
{
    public static UserDal UserRepository { get; set; } = new UserDal();

    public static void GenerateTemplates(int[] ids)
    {
        string[] names = UserRepository.Query()
            .Where(u => ids.Contains(u.Id))
            .Select(u => u.UserName)
            .ToArrayAsync().Result;

        string messageTemplate = "Hello, dear {0}. Happy Birthday!";
        string directoryPath = "C://templates/birthdays/";

        foreach (var name in names)
        {
            System.IO.File.WriteAllText(directoryPath + name, string.Format(messageTemplate, name));
        }
    }
}