jeudi 5 novembre 2015

What is the best Design pattern to use in the below scenario

I am planning on refactoring some legacy code which authorizes various views/view model methods / commands. I am sick of looking at this below code. I would like to use strategy pattern. Any suggestions ?

 public static bool AuthorizeGeneral(string rule)
    {
        switch (rule)
        {
            case RuleFilterNoteType:
                return
                    isInRoleSkipManger() ||
                    isInRole(RoleNegotiationManager) || isInRole(RoleNegotiationCollector) ||
                    isInRole(RoleLitigationManager) || isInRole(RoleRecoveryVicePresident) || isInRole(RoleSkipCollector) ||
                    isInRole(RoleLitigationAdministrator) || isInRole(RoleBankruptcyManager) ||
                    isInRole(RoleBankruptcyAdministrator);
            case CanEditExceptionQueueRule:
                return
                    isInRole(RoleLitigationManager) || isInRole(RoleBankruptcyManager) || isInRole(RoleCOO) || isInRole(RoleEVP) ||
                    isInRole(RoleRecoveryVicePresident) || isInRole(RoleNegotiationManager);

................................. case 150 ...............case 200

                                    }
    }

Aucun commentaire:

Enregistrer un commentaire