我有邊緣的界面:如何將單例傳遞爲泛型類型參數?
public interface IEdge<TPoint, TFactory>
where TPoint : IPoint
where TFactory : IEdgeFactory<TPoint>
{
TPoint Begin { get; }
TPoint End { get; }
void Divide();
}
邊緣可以被劃分那些生產嵌套邊緣。新的邊使用工廠模式創建:
public interface IEdgeFactory<TPoint>
where TPoint : IPoint
{
IEdge<TPoint> Create(TPoint begin, TPoint end)
}
我希望能夠實例我IEdge
實現內的工廠。通常我會這樣做,即使用public static IEdgeFactory<TPoint> Instance { get; }
,但我無法在界面中定義它。
那麼有沒有辦法將singleton工廠作爲類型參數傳遞並給實現一個實例化的方法?
你可以有一個抽象類'EdgeBase'實現接口'IEdge',並具有'靜態IEdgeFactory Instance' –
SimpleVar