class Program
{
static void Main(string[] args)
{
Master m = new Master(37);
Content c = new Content(m);
}
}
我定义了两个类。第一个如下:
internal class Content
{
private Master _parentMaster;
private Content _contentChildren;
#region Constructor
internal Content(Master master)
{
this._parentMaster = master;
}
internal Content(Master master, long contentId)
{
this._parentMaster = master;
_getContent(contentId);
}
#endregion
#region Private Methods
private void _getContent(long contentId)
{
contentRepository.getContent(contentId, _parentMaster.MasterId);
}
#endregion
#region Internal Methods
internal void AddContent()
{
// code omitted
}
internal void UpdateContent()
{
// code omitted
}
internal void GetChildren()
{
// code imitted
}
internal void GetRootContent()
{
// code omitted
}
#endregion
#region Properties
// code omitted
#endregion
}
第二个:
public class Master
{
private MasterEntities _master;
private List<Master> _masters;
#region Constructor
internal Master()
{
_master = new MasterEntities();
}
internal Master(long masterId)
{
_getMaster(masterId);
}
#endregion
#region Private Methods
internal void _getMaster()
{
// code omitted
}
#region Properties
internal long MasterId
{
get
{
return _master.id;
}
set
{
_master.id = value;
}
}
// code omitted
#endregion
}
这是实现这两个类的正确方法吗?还是更好地实现嵌套类?如果是,如何使用嵌套类获得“Main”中所述的相同结果?