Personally, I think method overloading to return different types is a bad idea. Those methods could be named 'addInts' and 'concatStrings' and be much more easily understood than 'addValues' or something similar.
What does everyone think about overloading methods and just having a call to the base method. For example..
int addInts(list<int> addThese)
{
Int added = 0;
Foreach(int add in addthese)
{
Added += add;
}
Return added;
}
Int addThese(int x, int y)
{
addThese(new list<int>() {x, y}
}
Int addThese(int x, int y, int z)
{
addThese(new list<int>() {x, y, z}
}
I know this example it makes more sense to just call the original, but with more complex methods where you may only need 5 of 8 parameters passed It applies. I'm not advocating for this, I just see it often at work and Think it'd Be better off as It's own method.
1 comment
1 u/ThatsSoJewish 10 Feb 2017 17:35
Personally, I think method overloading to return different types is a bad idea. Those methods could be named 'addInts' and 'concatStrings' and be much more easily understood than 'addValues' or something similar.
What does everyone think about overloading methods and just having a call to the base method. For example..
I know this example it makes more sense to just call the original, but with more complex methods where you may only need 5 of 8 parameters passed It applies. I'm not advocating for this, I just see it often at work and Think it'd Be better off as It's own method.