Earlier quoted context omitted.
The type enhancement means that traits could replace classes completely in scala, which is kind of exciting. The problem with traits is that state must be inlined even if implementations are not (so they are a mixture of mixins and small talk style traits). I'm well versed in how they are implemented in scalac. What non-CL mixins are not inheritance based? Python?
Oh absolutely, the type enhancement is what makes it so interesting to use, but the point is that it's not necessary for it to be a mixin. It's a very nice extra. I'm not sure about python, but Ruby completely inlines the mixin's code. It needs to do this because instance variables can be created anywhere, including from inside the mixin, but they still need to apply to the object of the actual class. This gives inte…
Why composition is often better than inheritance
91–97 of 97 posts
Re: Why composition is often better than inheritance
#92Re: Why composition is often better than inheritance
#93Earlier quoted context omitted.
> While it's a well-written article, it really seems like beating a dead horse I graduated college about 10 years ago, and I was never taught anything near composition over inheritance. I was told about inheritance, but had to learn from other coworkers and experience that composition is much favored over inheritance. Now I mentor a number of junior developers and they need to be told composition over inheritance oft…
"I was told about inheritance, but had to learn from other coworkers and experience that composition is much favored over inheritance." You weren't taught that, because it isn't true. Inheritance is appropriate sometimes, composition at other times. In particular, when a two objects are modeled by an ISA relationship, you should use inheritance. When they're modeled by HASA, you should use composition. A Dog is not a…
I think there is probably a lot of room for debate on this.
(Edited to make it less pithy and therefore probably much less irksome)
Re: Why composition is often better than inheritance
#94Re: Why composition is often better than inheritance
#95Re: Why composition is often better than inheritance
#96Re: Why composition is often better than inheritance
#97Earlier quoted context omitted.
The stuff you mix in has code. Interfaces do not.
What code do you mean? He only wrote "pass". I guess I'm confused because he still used inheritance.