liveBook · Manning

Inheritance

As explained in Data-Oriented Programming: Reduce software complexity

Class inheritance is a language mechanism in which a class derives behavior and structure from one or more parent classes.

Inheritance lets a class derive behavior and structure from a parent class. In a library system, Members and Librarians can inherit login behavior from User, avoiding duplicated code when requirements are known in advance. section 1.1.2 section 1.2.4

The tidy hierarchy becomes less tidy when requirements change. Adding VIPMember sounds small: VIP members are still members, but they may add book items independently. Yet the reusable operation is locked inside Librarian::addBookItem, so reusing it requires another class relationship rather than simply moving data through a shared operation. section 1.2.4

The deadline feature

With two days left before release, Nancy requests VIP members. Theo must decompose the request into “VIP members are library members” and “VIP members can add book items,” exposing how class-bound behavior turns a supposedly tiny change into hierarchy work. section 1.2.4

Figure 1.15 The part of the class diagram that deals with members and librarians

Use the member-and-librarian class diagram to inspect the inheritance structure behind shared login behavior. section 1.2.4

How Data-Oriented Programming: Reduce software complexity covers it

How deep it goes
Explains inheritance through UML notation and a changing library requirement, but stops short of implementation details.
Examples
Uses User, Member, Librarian, VIPMember, login behavior, and adding book items as concrete design examples.
What it assumes
Introduces the relevant object-oriented vocabulary while assuming only a basic class-and-method model.
What you can do after
Evaluate how a new requirement may increase class-hierarchy complexity when behavior is locked inside methods.
How it connects
Connects inheritance with class hierarchies, superclasses, object-oriented programming, and the separation of code from data.

Also explained in

Compare how 19 books explain inheritance →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming: Reduce software complexity. The section links point to the parts of the book it draws on.