I want to to extend a trait within a trait, like this:
trait NodeTypes {
trait Node {
def allNodesHaveThis: Int
}
}
trait ScrumptiousTypes e
use type also fix the issue
trait NodeTypes {
trait Node {
def allNodesHaveThis: Int
}
}
trait ScrumptiousTypes extends NodeTypes {
trait Node extends super.Node {
def scrumptiousness: Int
}
type ScrumptiousTypesNode = this.Node
}
trait YummyTypes extends NodeTypes {
trait Node extends super.Node {
def yumminess: Int
}
type YummyTypesNode = this.Node
}
object Graph extends NodeTypes with ScrumptiousTypes with YummyTypes {
case class Node() extends ScrumptiousTypesNode with YummyTypesNode {
override def allNodesHaveThis = 1
override def scrumptiousness = 2
override def yumminess = 3
}
}
------v2------- use object contain to Node , but since path depend it is not a good idea , and maybe It will be problems
trait NodeTypes {
trait Node {
def allNodesHaveThis: Int
}
}
object NodeTypes extends NodeTypes
trait ScrumptiousTypes extends NodeTypes {
trait Node {
def scrumptiousness: Int
}
type ScrumptiousTypesNode = this.Node
}
object ScrumptiousTypes extends ScrumptiousTypes
trait YummyTypes extends NodeTypes {
trait Node {
def yumminess: Int
}
type YummyTypesNode = this.Node
}
object YummyTypes extends YummyTypes
trait Nodes {
trait Nodes extends NodeTypes.Node with YummyTypes.Node with ScrumptiousTypes.Node
}
object Graph extends Nodes {
case class Nodes() extends super.Nodes {
override def yumminess: Int = 1
//
override def scrumptiousness: Int = 2
override def allNodesHaveThis: Int = 3
}
}