public class ExtendedProfile:Profile 建立Profile子类ExtendedProfile,他可以继承Profile中的方法
{
protected string _address1; //子类ExtendedProfile的属性
protected string _address2;
protected string _city;
protected string _state;
protected string _postal;
protected string _description;
public ExtendedProfile() //子类ExtendedProfile中属性的初始值
{
_address1 = "清华大学";
_address2 = "清华大学物理实验室";
_city = "北京";
_state = "北京";
_postal = "100024";
_description = "教授";
}
public override void setPhonenumber(string phonenumber) //继承类Profile中的setPhonenumber()方法
{ //setPhonenumber()方法的重载
_phonenumber = phonenumber;
}
public string getAddress1() //子类ExtendedProfile中的方法getAddress1(),以下类推
{
return _address1;
}
public string getAddress2()
{
return _address2;
}
public void setAddress(string address1,string address2)
{
_address1 = address1;
_address2 = address2;
}
public string getCity()
{
return _city;
}
public void setCity(string city)
{
_city = city;
}
public string getState()
{
return _state;
}
public void setState(string state)
{
_state = state;
}
public string getPostal()
{
return _postal;
}
public void setPostal(string postal)
{
_postal = postal;
}
public string getDescription()
{
return _description;
}
public void setDescription(string description)
{
_description = description;
}
public override void save() //调用接口ISaveData()中的方法save(),save()方法的重载,由于多态性
{ //子类ExtendedProfile可以自定义并修改save()方法
string _document = "d:\\myweb2\\saidy.xml";
XmlTextWriter writer = null; //保存为一个Xml文件
try
{
writer = new XmlTextWriter(_document,null);
writer.Formatting = Formatting.Indented;
writer.WriteStartDocument(false);
writer.WriteDocType("Profile",null,null,null); //表示<!DOCTYPE Profile>
writer.WriteStartElement("Profile"); //生成根元素
writer.WriteElementString("firstname",_firstname); //生成子元素 <firstname>_firstname</firstname>
writer.WriteElementString("lastname",_lastname);
writer.WriteElementString("phonenumber",_phonenumber);
writer.WriteElementString("address1",_address1);
writer.WriteElementString("address2",_address2);
writer.WriteElementString("city",_city);
writer.WriteElementString("state",_state);
writer.WriteElementString("postal",_postal);
writer.WriteEndElement();
writer.Flush();
writer.Close();
}
catch(Exception e