【发布时间】:2014-04-01 21:16:19
【问题描述】:
我得到一种树继承关系。每个上层节点都可以视为模板值。并且较低的节点具有完全相同的值和一些新列(值的种类)。
我想知道是否有简单的方法可以将这些值从上层节点传递到下层节点。
我的代码如下:
public class rootData
{
public long sID;
public string sName;
public string title;
public string country;
<many....many...columns>
};
public class sub1 : rootData
{
public void load(rootData template)
{
this.sID= template.sID;
this.sName= template.sName;
this.title= template.title;
this.country= template.country;
<many....many...asigns>
}
public int sNumberA;
public int sNumberB;
};
我想知道:有没有像这样写的方法
this.everything=template.everything
替换那么多行的赋值:
this.sID= template.sID;
this.sName= template.sName;
this.title= template.title;
this.country= template.country;
<many....many...asigns>
【问题讨论】:
-
如何将关系从“is-a”更改为“has-a”?
-
是的,我只想要“has-a”然后怎么做?
-
我强烈建议将这些字段转换为属性。
-
在这个例子中,如果我改变模板的值,它应该改变派生的 sub1 值吗?
-
实际上...上限值永远不会改变...永远不要考虑这个
标签: c# oop inheritance multiple-inheritance