Last active
August 24, 2017 15:44
-
-
Save jiamingd/48c9c0ca910beb42bf59a13cfd9688bc to your computer and use it in GitHub Desktop.
Demo how to cake multiple traits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is to demo cake pattern