Last active
January 5, 2018 15:12
-
-
Save kahneraja/d1078f95ee09091018a18afa372f1794 to your computer and use it in GitHub Desktop.
Exploring Interfaces in Scala
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
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". |
Author
kahneraja
commented
Jan 5, 2018
- 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?
Exploring Super Interfaces in Java 8.
https://gist.github.com/kahneraja/4199a2ccb621a7e15842a4d64a9d4f38
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment