Case: Several methods with same params validation inside, like:
public Response method1(...params...)
{
if (someCondition)
{
//do some stuff with side effects
...
return Response1;
}
if (someCondition2)
{
//do another stuff with side effects
...
return Response2;
}
if (someCondition3)
{
//do another stuff with side effects
...
return Response3;
}
// Do something
return Response4;
}
and
public Response method2(...params...)
{
if (someCondition)
{
//do another stuff with side effects
...
return Response1;
}
if (someCondition2)
{
//do another stuff with side effects
...
return Response2;
}
if (someCondition3)
{
//do another stuff with side effects
...
return Response3;
}
// Do something 2
return Response4;
}
Etc.......... How Can i avoid duplication without throwing exception?
UPD: I try to explain why it is not duplicate of Style for control flow with validation checks : In this case in both functions after "someCondition" validation we have some code with side effects in function, not just return response, so i cant just make some method (Specification pattern) that do validation and return response because of additional logic after validate param.