I have a function in my C# class :
class Fun {
private string waterGun;
private string jacket;
void HaveSomeFun(bool summers) {
waterGun = <Some Value>
jacket = <Some Other Value>
validate();
if(summers) {
Console.WriteLine("Using {0}", waterGun);
} else {
Console.WriteLine("Using {0}", jacket);
}
}
private void validate() {
ArgumentValidationHelper.ValidateNotNullOrEmpty("WaterGun", this.waterGun);
ArgumentValidationHelper.ValidateNotNullOrEmpty("Jacket", this.jacket);
}
}
I am making the variables instance members just for validation. Does it make sense to increase the scope of variables from a method to a class just for validation ?
Is there any other (better) way for achieving this functionality where the validation is centralized and variables are not required to be class members ?