特定のクラスを new でインスタンス化することを避け、強制的にファクトリ クラスを使用したいと考えています。
しかし、私はそれを行う方法を理解していません。
誰かが私に小さなサンプルを見せてもらえますか?
よろしくお願いします。
特定のクラスを new でインスタンス化することを避け、強制的にファクトリ クラスを使用したいと考えています。
しかし、私はそれを行う方法を理解していません。
誰かが私に小さなサンプルを見せてもらえますか?
よろしくお願いします。
ここから始めるべきことがあります。特定のタイプのインスタンスを newing によってインスタンス化できるようにするかどうかを決定するために、独自のロジックを追加する必要があります。
public override ProblemCollection Check(Member member)
{
if (member is Method)
{
this.Visit(member);
}
return this.Problems;
}
public override void VisitConstruct(Construct construct)
{
base.VisitConstruct(construct);
if (!this.AllowTypeToBeNewed(construct.Type))
{
this.Problems.Add(new Problem(this.GetResolution(), construct));
}
}
private bool AllowTypeToBeNewed(TypeNode type)
{
throw new NotImplementedException();
}