Best practice for defining multiple traits that add behavior to classes that implement a particular trait

Let's say I have a number trait

that adds some behavior to the extending classes Actor

.

Each requires a small subset of the Actor

. Is it ok for everyone to expand Actor

as follows?

trait A extends Actor {
  def doAThing = { ... }
}
trait B extends Actor {
  def doBThing = { ... }
}
trait C extends Actor {
  def doCThing = { ... }
}

class D extends Actor with A with B with C

      

Or does each trait define the methods it needs from Actor

as abstract methods, so that they are exposed by a final, concrete class that is the only one that then extends Actor

?

+3


source to share


1 answer


Inheritance

trait A extends Actor

      

means that A

- Actor

. Another way is to useself-types



trait B {
  self: Actor =>
}

      

means it B

requires to be Actor

mixed.

See the linked question for details .

+6


source







All Articles