【发布时间】:2017-09-05 06:43:52
【问题描述】:
我对在基类中封装属性设置器有点困惑。
假设其中一些属性是在 base 构造函数中设置的,那么 setter 应该是私有的还是受保护的?
假设其中一些属性在 child 构造函数中设置,设置器应该是私有的还是受保护的?
为了更清楚,这里是一个具体的案例:
public abstract class Records
{
public string Date { get; protected set; }
public string Source { get; protected set; }
public string Type { get; protected set; }
public int Value { get; protected set; }
protected Records(string type, string source, int value)
{
Type = type;
Source = source;
Value = value;
Date = DateTime.Now.ToString("hh.mm.ss.ffffff");
}
}
public class NewDocumentRecord : Records
{
public NewDocumentRecord(string source, int value)
: base(ContentTypesString.DocumentNew, source, value)
{
Source = source;
Value = value;
}
}
【问题讨论】:
标签: c# oop properties encapsulation