Skip to content

Instantly share code, notes, and snippets.

@jiamingd
Last active August 24, 2017 15:44
Show Gist options
  • Save jiamingd/48c9c0ca910beb42bf59a13cfd9688bc to your computer and use it in GitHub Desktop.
Save jiamingd/48c9c0ca910beb42bf59a13cfd9688bc to your computer and use it in GitHub Desktop.
Demo how to cake multiple traits
object TeathCleans {
trait TeathClean {
def cleanTeath
}
trait SonicTeathClean extends TeathClean {
override def cleanTeath = {
println("supersonic cleaning")
}
}
trait NormalBrushTeathClean extends TeathClean {
override def cleanTeath = {
println("Just use brush to scrub")
}
}
}
object BodyWashs {
trait BodyWash {
def washBody
}
trait FaceWashOnly extends BodyWash {
override def washBody = {
println("only wash face")
}
}
}
import TeathCleans._
import BodyWashs._
trait GoBedProcedure extends TeathClean with BodyWash {
self : TeathClean with BodyWash =>
def cleanSequence = {
self.cleanTeath
println("and then")
self.washBody
}
}
case class KidGoBed(name: String) extends GoBedProcedure with NormalBrushTeathClean with FaceWashOnly
val felixGoBed = KidGoBed("Felix")
felixGoBed.cleanSequence
@jiamingd
Copy link
Author

This is to demo cake pattern

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment