0

So I get what we can do with traits but in what cases should we prefer their use to a concrete class ? I was told to use traits everywhere I can and when I need to instanciate something use a regular class.

Edit : I am actually asking about when to use a trait insted of a concrete class not an abstract one

blank_sam
  • 23
  • 9

1 Answers1

1

As it's often the case, there is no single rule, but I personally found useful a general suggestion give in Odersky/Spoon/Venners book "Programming in Scala".

It says if the behaviour will not be reused in other unrelated classes, use a concrete class. On the other hand, if you think you'll reuse that behaviour somewhere else in unrelated places, make it a trait.

mfirry
  • 3,634
  • 1
  • 26
  • 36