mercredi 20 janvier 2021

What pattern to use?

Problem: We have 2 and more Entities: Project and Task, these entities have services: ProjectService and TaskService. Most of the operations on entities are used like CRUD. And we have user roles, for each role in the service of each entity, the set of methods and parameters must be different. For example, in the project service, all methods are available for the Admin role, but only a few for the Manager role, and the implementation of the method may differ depending on the role. For example, the Manager role should receive only his projects and tasks. What is the best pattern to apply to this solution?

class ProjectService {
    public void GetAll() {...}
    public void GetById() {...}
    public void Create() {...}
    public void Close() {...}
    public void Delete() {...}
}

class TaskService {
    public void GetAll() {...}
    public void GetById() {...}
    public void Create() {...}
    public void Close() {...}
    public void MoveToBoard() {...}
    public void Delete() {...}
}

public class AdminProjectService : ProjectService {} // inherits all methods
public class AdminTaskService : TaskService {} // inherits all methods

public class ManagerProjectService : ProjectService { // should contain 3 methods instead of 5
    public void GetAll() {...} // should show only projects of this manager
    public void GetById() {...}
    public void Create() {...}
}

public class ManagerTaskService : TaskService { // should contain 4 methods instead of 6
    public void GetAll() {...} // should show only tasks of this manager
    public void GetById() {...}
    public void Create() {...}
    public void Close() {...}
}

Aucun commentaire:

Enregistrer un commentaire