これは私の最初の投稿なので、いくつかの間違いがあることを事前にお詫びします。また、英語は私の母国語ではありません。何が良いのか、その理由は何ですか? 私は他に 2 人の人と作業していて、さまざまなタイプの人を表す 4 つのクラスがあり、各クラスには約 15 の属性があることを覚えておいてください。
A - 同じクラス内のクラスの各属性の検証を作成します。
public class People
{
string name { get; set; }
private void ValidateName()
{
if(this.name.Contains("0", ..., "9"))
throw new Exception("Name can't contain numbers.");
}
}
または B - 検証専用のクラス (おそらく静的クラス?) を作成します。
public class People
{
string name { get; set; }
}
static class Validation
{
static void Name(string name)
{
if(name.Contains("0", ..., "9"))
throw new Exception("Name can't contain numbers.")
}
}
//and then somewhere in the code I call the Validation.Name(name) to verify if the code is ok.
3 番目のより適切なオプションはありますか? 例外を使用することが道であるかどうかさえわかりません。
前もって感謝します!