我很羞愧,看了公司大神以前用工厂模式做的项目。很自卑。。
问一句:
父类
public abstract class AbstractCalculator
{
protected int _year;
protected int _month;
protected string _caseid;
protected string _houseid; protected OperationArg OArg;
protected Fee fee;
protected Rebate rebate;
protected DataBuilder Dbuilder;
protected Account balance;
protected string _loginID;
protected int _units; public AbstractCalculator(int year, int month, string houseid, string caseid) //父类构造函数
{
this._year = year;
this._month = month;
this._houseid = houseid;
this._caseid = caseid; OArg = new OperationArg(this._caseid, this._houseid);
fee = new Fee(caseid);
rebate = new Rebate(caseid);
Dbuilder = new DataBuilder(this._year, this._month, this._houseid, this._caseid);
}
}
子类
/// <summary>
/// 信息费计算器
/// </summary>
public class MessageFeeCalculator : AbstractCalculator
{
public MessageFeeCalculator(int year, int month, string houseid, string caseid)
: base(year, month, houseid, caseid) //这句话,是继承用父类的构造函数??干什么用的?希望解释清楚。。
{ }
}
问一句:
父类
public abstract class AbstractCalculator
{
protected int _year;
protected int _month;
protected string _caseid;
protected string _houseid; protected OperationArg OArg;
protected Fee fee;
protected Rebate rebate;
protected DataBuilder Dbuilder;
protected Account balance;
protected string _loginID;
protected int _units; public AbstractCalculator(int year, int month, string houseid, string caseid) //父类构造函数
{
this._year = year;
this._month = month;
this._houseid = houseid;
this._caseid = caseid; OArg = new OperationArg(this._caseid, this._houseid);
fee = new Fee(caseid);
rebate = new Rebate(caseid);
Dbuilder = new DataBuilder(this._year, this._month, this._houseid, this._caseid);
}
}
子类
/// <summary>
/// 信息费计算器
/// </summary>
public class MessageFeeCalculator : AbstractCalculator
{
public MessageFeeCalculator(int year, int month, string houseid, string caseid)
: base(year, month, houseid, caseid) //这句话,是继承用父类的构造函数??干什么用的?希望解释清楚。。
{ }
}
{
this._year = year;
this._month = month;
this._houseid = houseid;
this._caseid = caseid; OArg = new OperationArg(this._caseid, this._houseid);
fee = new Fee(caseid);
rebate = new Rebate(caseid);
Dbuilder = new DataBuilder(this._year, this._month, this._houseid, this._caseid);
}
给属性赋值啊
: base(year, month, houseid, caseid)
构造函数 :构造函数?
是 构造函数 继承 构造函数吗?1楼解释清楚再走。谢谢
: base(year, month, houseid, caseid) { }
//这句话,的意思是:通过子类的构造函数,给父类的构造函数付值
private string _xxx;
...
public MessageFeeCalculator(int year, int month, string houseid, string caseid, string xxx)
: base(year, month, houseid, caseid)
{
this._xxx = xxx;
}
只有最后一个参数是对本类的操作 其他的参数实际上都赋值给了父类(接收这些参数的父类字段有些可能是子类无访问权限的private) 调用的是父类的方法