Created
November 11, 2014 16:14
-
-
Save scottashipp/d72a2b567a388bf8516c to your computer and use it in GitHub Desktop.
Members.scala - basic demo of Scala overriding 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
abstract class Member { | |
def memberId: Int | |
def firstName: String | |
def lastName: String | |
} | |
class BasicMember(val memberId: Int, val firstName: String, val lastName: String) extends Member | |
trait BuckooBucks { | |
var buckooBalance: Int = 1000 | |
def addBucks(amt: Int) = { | |
buckooBalance += amt | |
} | |
} | |
class BuckooMember(memberId: Int, firstName: String, lastName: String) extends BasicMember(memberId: Int, firstName: String, lastName: String) with BuckooBucks | |
trait DoubleBuckooBucks extends BuckooBucks { | |
abstract override def addBucks(amt: Int) = { | |
val doubledAmount = amt * 2 | |
super.addBucks(doubledAmount) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment