In Scala, sometimes class extends a trait to provide some methods to extending class inside.
import org.scalatest._
class ExampleSpec extends FlatSpec with Matchers { ...
Matchers
trait provides useful method like startWith
, endWith
or include
.
string should startWith ("Hello")
string should endWith ("world")
string should include ("seven")
Problem is simple, "ExampleSpec
is not Matchers
".
Extends for feature breaks OOP fundamental principle.
This extends
is confusing especially for code-reader or newcomer.
I think we should use import
like import scalatest.matchers._
.
This doesn't taint inheritance tree.
Is extends for feature bad practice in Scala ? or reasonable extends usage ?