jeudi 6 octobre 2022

Design Pattern / Naming Conventions Suggestions

I'm trying to figure out if there's a specific design pattern for a singleton class that takes a bunch of parameters from different sources and constructs a complex object? I've been racking my brain around what naming conventions to use. I've been taking the approach of calling them builders, but a builder from my understanding has multiple methods to build up the object before using the final build method - which generally isn't required for my approach. It also singleton and isn't initialised every time it build object. It's also not really a factory pattern either.

Simplistic Example;

 public class Person
    {
        
    }
        
    public class PersonRoles
    {
        
    }
        
    // Complex object
    public class PersonIdentity
    {
        public Person Person { get; set; }
        public IEnumerable<PersonRoles> PersonRoles { get; set; }
    }
        
    // Responsible for taking different source data and constructing
    // object result. Generally a singleton.
    public class PersonIdentityBuilder
    {
        private readonly ILogger _logger;
        private readonly IMapper _mapper;
        private readonly Settings _settings;
        
        public PersonIdentityBuilder(Settings settings, ILogger logger, IMapper mapper,)
        {
            _logger = logger;
            _mapper = mapper;
        }
    
        public BuildPersonIdentityResult Build(string name, string phone, IEnumerable<KeyValuePair<string, string>> rolesDepartments) =>
            new BuildPersonIdentityResult();
    }
        
    public class BuildPersonIdentityResult
    {
        public PersonIdentity PersonIdentity { get; set; }
        public bool Successful { get; set; }
        public bool Message { get; set; }
    }

Aucun commentaire:

Enregistrer un commentaire