Reputation: 25
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
Upvotes: 0
Views: 184
Reputation: 3692
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.
Upvotes: 1