lundi 21 mai 2018

Refactoring if statements when changing same value on different conditions

I have been working on refactoring some code and then i make something like this. Main idea is that i have couple Methods which contains implementations and they change referenced string variable name in my case.

What i don't like here is situation that in every if statement returning same variable (but with different result).

So my question does someone have better idea for eventually refactoring this? Is there any problem doing this in if statements (from logical, clean code side etc).

 private string GenerateNameFrom(IRow row)
        {
            string name= string.Empty;
            if (Method1(name))
            {
                return name;

            }else if(Method2(name))
            {
                return name;
            }
            else if (Method3(name))
            {
                return name;
            }else
            {
                return "Null";
            }
        }

Aucun commentaire:

Enregistrer un commentaire