Using Inheritance to Share Implementations

Don't Repeat Yourself.

If you implement some behavior by writing the same code at several different places in your program, that behavior will probably break when someone eventually tries to improve or repair it, and overlooks one of the several different places where that behavior needs to be updated.

Inheritance allows several different classes to share a common implementation of their common behavior.

Inheritance is often convenient, but it is also less general and more fragile than composition and delegation.


Creative Commons License © Mitchell Wand, 2012-2015
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.
The work has been modified by William D Clinger in these ways and more: conversion from PowerPoint to HTML, and from Racket to Java.

For debugging: Click here to validate.