AlgoViz

IS-A and HAS-A

easy 40 min

IS-A says that an object is a kind of something and can stand in for it.

Watch lesson4:45

Where it shows up

The same pattern appears across everyday software.

  • java.util.Stack

    It extends Vector, so a stack can be changed in the middle. The documentation recommends Deque and its implementations in preference to it.

  • java.util.Properties

    Because it inherits from Hashtable, `put` works on it. The documentation strongly discourages that, since it lets in values that are not strings.

  • ArrayList

    Both relations: it is an AbstractList and implements List, and it has an array that is replaced by a bigger one when it is full.

  • React

    The React documentation recommends composition instead of inheritance to reuse code between components.

  • Go

    The Go FAQ explains why there is no type inheritance. Effective Go describes borrowing pieces of an implementation by embedding types in a struct.

  • Unity

    A GameObject gets its abilities from components that are added to it. The Unity manual has its own section on adding components.

  • Java threads

    Extending Thread makes the job a thread. Passing a Runnable gives a thread a job. The second lets the same job run in another place.

  • Single table inheritance

    Martin Fowler's catalogue describes a hierarchy stored in one table with columns for the fields of all classes.

  • Qt object trees

    Every QWidget is a QObject, and an object has children. The documentation explains that the children are deleted when the parent is.