Skip to content

Instantly share code, notes, and snippets.

@kahneraja
Last active January 5, 2018 15:12
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 kahneraja/d1078f95ee09091018a18afa372f1794 to your computer and use it in GitHub Desktop.
Save kahneraja/d1078f95ee09091018a18afa372f1794 to your computer and use it in GitHub Desktop.
Exploring Interfaces in Scala
trait Vehicle {
def drive = {
println("drive vehicle")
}
}
trait Boat extends Vehicle {
override def drive = println("drive boat!")
}
trait Plane extends Vehicle {
override def drive = println("drive plane!")
}
trait MockPlane extends Vehicle {
override def drive = println("let's mock this!")
}
class Seaplane extends Plane with Boat {
}
val s = new Seaplane
s.drive
val testS = new Seaplane with MockPlane
testS.drive
// #TraitLinerization. Runs the last "with" trait. In this case it will "drive boat".
@kahneraja
Copy link
Author

  • what are the primary differences between java and scala in regards to interfaces and classes?
  • are companion objects an anti pattern?
  • how do we maintain the notion of a single responsibility given the scope of class can be possible static and an instance?
  • when should we have static methods alongside instance methods? why?
  • should static methods belong to a different class? AppleService.scala (instance methods) + AppleUtils.scala (static methods)
  • should traits contain code? should interfaces offer default methods?
  • do we generally prefer composition over inheritance?
  • what are the benefits of scala over java?
  • Do we want to take advantage of Trait Linerization as a test double strategy?
  • Should we take an Trait Linerization "mixin" approach to these static functions?

@kahneraja
Copy link
Author

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