あなたの質問は、優れたプログラミングの実践とthere could be multiple solution or design technique for this question
.
私はこのようなクラスを作成します -
// create interface for providing {x} features
public interface IBObj_Sf
{
...
...
}
// create class which provides {x} features of IBObj_Sf interface
public class BObj_Sf : IBObj_Sf
{
...
...
}
// now implement BObj_Sub class like -
public class BObj_Sub
{
// mark as readonly depending it is modifiable or
// not withing BObj_Sub's lifecycle
private readonly IBObj_Sf _Sn;
public BObj_Sub(IBObj_Sf sn)
{
_Sn = sn;
}
public BObj_Sf Sn
{
get { return _Sn; }
private set { _Sn = value; }
}
}
使用法:
BObj_Sf sf = new BObj_Sf();
BObj_Sub sub = new BObj_Sub(sf);
利点 :明日、BObj_Sf
新しいクラスに変更したい場合BObj_Xf
は、次の行のみが新しいクラスと共に変更されます。-
BObj_Xf xf = new BObj_Xf();
BObj_Sub sub = new BObj_Sub(xf);
コードインBObj_Sub
は変更されません。