You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a number of methods, each of which checks the same set of conditions and returns a null value if none of the conditions are met, otherwise returns an object of different classes.
Is there a way to not have to write all of these terms for each function and use less code?
public A methode1()
{
if ///someCondition
return null
else if ///someCondition
// do some thing1
return A("yyyy")
else if ///someCondition
// do some thing1
return A("zzzz")
else
return Error() // or return null
}
public B methode2()
{
if ///someCondition
return null
else if ///someCondition
// do some thing2
return B("ffff")
else if ///someCondition
// do some thing2
return B("tttt")
else
return Error() // or return null
}
public C methode3()
{
if ///someCondition
return null
else if ///someCondition
// do some thing3
return C("nnn")
else if ///someCondition
// do some thing3
return C("mmm")
else
return Error() // or return null
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a number of methods, each of which checks the same set of conditions and returns a null value if none of the conditions are met, otherwise returns an object of different classes.
Is there a way to not have to write all of these terms for each function and use less code?
Beta Was this translation helpful? Give feedback.
All reactions