有沒有在我的庫摘要中實現「CreateNode」方法的方法?或者這隻能在庫外的客戶端代碼中完成?我目前得到的錯誤「無法創建抽象類或接口的實例「ToplogyLibrary.AbstractNode」如何在抽象類中創建對象而不需要實現知識?
public abstract class AbstractTopology<T>
{
// Properties
public Dictionary<T, AbstractNode<T>> Nodes { get; private set; }
public List<AbstractRelationship<T>> Relationships { get; private set; }
// Constructors
protected AbstractTopology()
{
Nodes = new Dictionary<T, AbstractNode<T>>();
}
// Methods
public AbstractNode<T> CreateNode()
{
var node = new AbstractNode<T>(); // ** Does not work **
Nodes.Add(node.Key, node);
}
}
}
public abstract class AbstractNode<T>
{
public T Key { get; set; }
}
public abstract class AbstractRelationship<T>
{
public AbstractNode<T> Parent { get; set; }
public AbstractNode<T> Child { get; set; }
}
聽起來不錯。然而,使用該方法的調用者在使用mehod時是否必須通過該類型? – Greg 2010-05-11 01:33:29