Ok, so I am developing a class here, and I have two options. I can either write several methods, or one method that takes on the value of Enum.
I am trying to find a better way to do this.
Let's take an example:
public class myClass
{ ...
public void DoStuff1()
{ ... Do Stuff ... }
public void DoStuff2()
{ ... Do Stuff ... }
public void DoStuff3()
{ ... Do Stuff ... }
}
Well, everything makes sense, now an alternative way would be:
public class myClass
{ ...
public Enum Option
{
Option1,
Option2,
Option3
}
public void DoStuff(Option option)
{ ... Do Stuff ... }
}
In terms of DRY, they are not so bad, because the code calls internal methods in many ways, so it selects only what is visible to the user.
So, what do you prefer, why, and are there any recommendations around this?
source
share