Created
February 14, 2016 06:47
-
-
Save Saheb/5b0d81b190fe2ace3f8a to your computer and use it in GitHub Desktop.
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
// Legacy | |
abstract class Lannister { | |
def payTheirDebts: Boolean | |
def trueLannister = payTheirDebts | |
def debt: Int | |
def addToDebt(amount: Int): Int | |
} | |
//Father | |
trait Tywin extends Lannister{ | |
override def payTheirDebts = true | |
def addToDebt(amount: Int): Int | |
} | |
// Son | |
trait Tyrion extends Tywin { | |
override def payTheirDebts = true | |
abstract override def addToDebt(amount: Int) = super.addToDebt(amount*2) | |
} | |
class Shae extends Tywin { | |
def debt = 100 | |
def addToDebt(amount: Int) = debt + amount | |
} | |
object GameOfThrones extends App{ | |
val leon = new Shae with Tyrion | |
println(leon.addToDebt(100)) // 300 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment