Skip to content

Instantly share code, notes, and snippets.

@scottashipp
Created November 11, 2014 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottashipp/d72a2b567a388bf8516c to your computer and use it in GitHub Desktop.
Save scottashipp/d72a2b567a388bf8516c to your computer and use it in GitHub Desktop.
Members.scala - basic demo of Scala overriding traits
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