scala - Should we always use `override` in Trait -
should utilize override in trait solve preemptively diamond inheritance issue ?
let's see illustration explain point :
trait s { def : string } trait extends s { override def = "a" } trait b extends s { override def = "b" } class c extends b without override, next doesn't compile.
using override create compile, real question is: trying achieve?
in scala, traits you're extending linearized. means that
class c extends b new c().get will produce "b"
but
class c extends b new c().get will produce "a" instead.
so expect? speaking, depending on order of inheritance solving diamond problem seems terrible design selection (while there legitimate uses of language feature, stackable trait pattern)
so, original question, should utilize override? no, should avoid diamonds in inheritance hierarchies.
scala diamond-problem
No comments:
Post a Comment