|
|
|
|
|
by andybak
4359 days ago
|
|
The Wikipedia article chton mentions (https://en.wikipedia.org/wiki/Composition_over_inheritance) ends with the following when discussing the drawback of composition (boilerplate for forwarding methods): "This drawback can be avoided by using traits or mixins." Now this is where things get a little blurry for me. Mixins can help with the main drawback of Composition - but Mixins ARE inheritance - so isn't this a contradiction? If I use PhysicsObjectMixin in my CharacterComposition class then I have to inherit from it. So aren't we back with the perils of inheritance? |
|
Remember that a mixin, by definition, isn't the same as inheritance. The methods, fields and properties are compiled into the class, not inherited. It's essentially a fancy way to 'include' a code file.