While reading and trying to get all the concepts behind scalable components in Scala from this, i still can't fully understand why this example should have self type:
abstract class Graph {
type Node <: NodeLike
trait NodeLike { // without self: Node => won't compile
def connectWith(n: Node) =
new Edge(this, n)
}
class Edge(from: Node, to: Node)
}
abstract type Node
is a subtype of NodeLike
and this
is an object of type NodeLike
which suites according to the given upper constraint. Any detailed explanation would be appreciated.