すべて同じインターフェイスを共有する、いくつかの検証エンティティを収集できるようにしたいと考えています。これは私が思いついたものです:
public interface Ivalidateable
{
bool IsValid(IValidateParam param);
}
public interface IValidateParam
{
}
public abstract EmployeeStrategy: Ivalidateable
{
public abstract bool IsValid(User user);
}
public abstract SpreadStrategy: IValidateable
{
public abstract bool IsAvlid(Campaign campaign);
}
public class User: IValidateParam
{}
public class Campaign: IValidateParam
{}
public EmployeeTypeStragtegy: EmployeeStrategy, IValidateable
{
public bool IsValid(User user)
{
if (new[]{'e',a','b}.Contains(user.userId.first().toString()))
return true;
return false;
}
}
public TrailSpreadStrategy: SpreadStrategy, IValidateable
{
public bool IsValid(Campaign campaign)
{
//logic goes here
}
}
public EvenpreadStrategy: SpreadStrategy:, IValidateable
{
public bool IsValid(Campaign campaign)
{
//logic goes here
}
}
public class ValidationFactory
{
private static List<IValidateable> stragtegies;
static ValidationFactory
{
strategies = new List<IValidateable>();
strategies.Add(new EmployeeTypeStragtegy());
strategies.Add(new TrailSpreadStrategy());
}
public bool IsValid(//Need to pass User/Campaign)
{
//what do I do here?
}
}
戦略をループして IsValid を確認できるように、ユーザー/キャンペーンを渡す最良の方法は何ですか?