我得到了一種樹繼承關係。每個上層節點可以被視爲模板值。而較低的節點具有完全相同的值和一些新的列(值的種類)。C#繼承傳遞模板值
我想知道是否有簡單的方法可以將這些值從上層節點傳遞到下層節點。
我的代碼,如:
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
,以取代asigns的很多很多行:
this.sID= template.sID;
this.sName= template.sName;
this.title= template.title;
this.country= template.country;
<many....many...asigns>
如何將關係從「is-a」改爲「has-a」? –
是的,我只是想「有一個」,那麼如何? –
我強烈建議將這些字段轉換爲屬性。 –