Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "class C extends A with B" and "class C extends B" when trait B extends trait A

When two traits are defined like this,

trait A
trait B extends A

what is the difference between these two.

class C extends B
class D extends A with B

I do not think it is necessary for class C or D to extends trait A since trait B already extends trait A.

Why is this often written "class D extends A with B" ?

like image 980
takhirata Avatar asked Jan 05 '12 09:01

takhirata


1 Answers

It's a pretty good question... I'll try to answer with a subjective response.

I guess that extends A mixin with B is important when the hierarchy will be linearized, in this particular case there is no differences but what if you mixin D with another trait E that reimplements some (but not all) functions from A which aren't well advised in B for your needs in D. So you'd have

class D extends A with E with B

Moreover in that case, we keep the meaning that D is a A

like image 81
Andy Petrella Avatar answered Sep 21 '22 03:09

Andy Petrella