Classical inheritance is obsolete

Axel Rauschmayer axel at rauschma.de
Sun Jun 30 15:11:44 PDT 2013


> I know that JavaScript doesn't lose its dynamic nature when we add class, but, to bring back an earlier example, say you start with:
> 
> Animal
> * Walking
>   * Human
>   * Ape
> * Flying
>   * Bird
>   * Bee
> * Swimming
>   * Fish
>   * Whale
> 
> Now you need alligator and duck. Alligator clearly needs walking and swimming, so you go to re-implement them as mixins, but now you have to refactor all the animals that already rely on those features -- or you end up reimplementing the functionality as mixins, and now you have the same features in two different places -- a violation of DRY. This is the duplication by necessity problem.

Honest question: how can this problem not be solved via ES6 classes plus mixins? The original hierarchy already feels wrong. Why not create a super-class Animal, with sub-classes Human, Ape, Bird, Bee, Fish, Whale plus the mixins Walking, Flying, Swimming?

> You have to refactor everything, or live with a design that is overly complicated and error prone.

I also don’t see why refactoring is such a bad thing: as your knowledge of the problem domain increases, the structure of your program evolves. Tool support for automated refactorings will improve (partially helped by classes). Additionally, unit tests minimize the risks of refactoring.

Axel

-- 
Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130701/ec919dbe/attachment.html>


More information about the es-discuss mailing list