die Vererbung (pl. -en) – inheritance
When one class inherits from another class, we say that the former is a subclass of the latter.
In German, the class that is being inherited from (the parent class) is called die Basisklasse (also Super-, Ober- or Elternklasse).
The child that does the inheriting (the child class) is called die abgeleitete Klasse. Other terms used are Sub-, Unter- and Kindklasse.
Inheritance is used to denote a “is-a” relationship.
For example, in the natural world, you would have dogs. Dog could be the parent class, and the subclasses that inherit from it could be specific breeds of dogs, like a Dalmatian or Labrador.
Parent classes make certain parts of their data or methods available to their subclasses, allowing for easy reuse. Dogs bark, so the Dog class could implement the bark method, which all its subclasses could use without having to implement the same class over.
That doesn’t mean that the child class must follow the implementation. Child classes can override the behaviour of a parent class method as well.
If this seems very similar to polymorphism, that’s because inheritance can be used to achieve polymorphism without much additional effort.
However, there’s a principle called Composition Over Inheritance (Komposition an Stelle von Vererbung) that advocates using composition.
Composition means that the class contains classes that implement the desired behaviour instead of inheritance. Part of it has to do with the constraints that inheritance places on a subclass, forcing it to be a type of its parent.
By contrast, composition typifies a “has-a” relationship, and provides more flexibility.
There’s something called multiple inheritance, where a child class can have multiple parent classes. I will be writing a separate post on that.
The word Verbergung comes from vererben + -ung
The suffix -ung is used to “form nouns from verbs, usually describing either an event in which an action is carried out, or the result of that action.”
Unfortunately, all Duden has to say about the origin of vererben is that it comes from Middle High German vererben.
But vererben itself is ver- + erben, and erben, well, means “to inherit”. (Vererben means to bequeath.)