I have a problem with correct implementation of factory. I have a base class User
public abstract class User() {}
there are several derived classes, like Admin, Editor, Maker, Checker and so on. Each user is created basing on collection of Claims. In the current implementation, there is a method inside User class:
public abstract class User()
{
public abstract bool ClaimsValidForUser(IEnumerable<Claim> claims);
}
implemented in each class
public class Editor()
{
public override bool ClaimsValidForUser(IEnumerable<Claim> claims)
{
//check claims and return true or false
}
}
in the factory class there is a method Create, which gets a collection of claims as a parameter, then it scans the assembly for all the classes which inherit from User. Next for every class it creates an instance of the class, then calls ClaimsValidForUser and proceeds with the process until a type of User is found which returns true. Is this a correct (clean) approach or maybe the factory should implement this logic and create the correct instance and return it. The current solution works, I am only asking about refactoring it to some design pattern with SOLID in mind.
Aucun commentaire:
Enregistrer un commentaire