假設我想創建一個簡單的圖表示,其中Vertex
和Edge
及其類型相互依賴。具體實現可以是這個樣子:相關類和類型
case class Edge(id: Int, label: String, endpoints: (Vertex, Vertex))
case class Vertex(id: Int, data: Data, edges: Map[Int, Edge])
Edge
取決於Vertex
,反之亦然。我真正想要的是id
,data
等具有通用類型。我想知道如何設計這個最好的方法?
trait Vertex[A, B] {
def id: A
def data: B
// What about types for the edges etc?
}
trait Edge[A, ...] {
def id: A
def label: String
def endpoints: (Vertex[...], Vertex[...])
}
一個簡單的例子將不勝感激。
正是我在想什麼。非常感謝! – chrsan