Implementation Inheritance Is Evil

Inheritance is a broad subject and there is a great deal of variation in precisely how various languages deal with it. Szyperski in ComponentSoftware identifies three uses for inheritance:

  1. subclassing: reusing code via implementation inheritance
  2. subtyping: the inheritance of interfaces
  3. a promise of substitutability: ie polymorphism

Few people would argue against subtyping or polymorphism, but subclassing is much more controversial. The fundamental problem is that subclassing breaks encapsulation. This has a variety of evil effects:

What is needed I think is a paradigm shift in language design: away from implementation inheritance and to a model based on composition or aggregation. The ScarletLanguage is attempting to do this. Scarlet objects are composed of multiple implementations that are treated as black boxes. This gives developers most of the benefits of single and multiple inheritance, but in a safer and more controlled way. It also allows for a high degree of dynamism (so plugins for example can modify existing object layouts).

--JesseJones


CategoryLanguage, CategoryLanguageFeature, CategoryEvil


EditText of this page (last edited April 22, 2010) or FindPage with title or text search