I
intrader
I have the following small classes:
//----------------code---------------
using System;
using System.Collections.Generic;
using System.Text;
namespace ValidatorsLibrary
{
public class ValidatorBase
{
protected static long _mask;
public ValidatorBase() { }
public static string Validate(string value, long mask)
{
_mask = mask;
//perform common validations here and return "" if OK or
// an error message.
return ""; //when Validate found no problems
}
}
public class FieldValidator : ValidatorBase
{
private FieldValidator() { } //no instantiation of this class
public static string Validate(string value, long mask)
{
string sErr = ValidatorBase.Validate(value, mask);
if (sErr.Length > 0) return sErr;
else
{
//do more validations specifice to this class
//these validations use local parameter mask
}
return sErr;
}
}
}
----------------------end of code-----------------------
Questions:
1. I gather that the class variable _mask is not thread safe. Is this so?
2. When FieldValidator.Validate is called, can other threads provide
values for its parameters while being passed to ValidatorBase.Validate?
3. How do I test for Thread Safety?
4. I am thinking of not using static methods and converting these
classes. Is a Singleton pattern appropriate?
Thanks
//----------------code---------------
using System;
using System.Collections.Generic;
using System.Text;
namespace ValidatorsLibrary
{
public class ValidatorBase
{
protected static long _mask;
public ValidatorBase() { }
public static string Validate(string value, long mask)
{
_mask = mask;
//perform common validations here and return "" if OK or
// an error message.
return ""; //when Validate found no problems
}
}
public class FieldValidator : ValidatorBase
{
private FieldValidator() { } //no instantiation of this class
public static string Validate(string value, long mask)
{
string sErr = ValidatorBase.Validate(value, mask);
if (sErr.Length > 0) return sErr;
else
{
//do more validations specifice to this class
//these validations use local parameter mask
}
return sErr;
}
}
}
----------------------end of code-----------------------
Questions:
1. I gather that the class variable _mask is not thread safe. Is this so?
2. When FieldValidator.Validate is called, can other threads provide
values for its parameters while being passed to ValidatorBase.Validate?
3. How do I test for Thread Safety?
4. I am thinking of not using static methods and converting these
classes. Is a Singleton pattern appropriate?
Thanks