liveBook · Manning

Superclass

As explained in The Well-Grounded Python Developer: How the pros use Python and Flask

A parent class is a class whose attributes and behavior are inherited by another class.

A superclass is a parent or base class whose attributes and behavior are inherited by a child, also called a subclass. Inheritance keeps shared functionality in one place, supporting the DRY principle while allowing specialized classes to add or modify behavior. section 4.1.3

Shapes and specialized behavior

A Shape superclass can hold shared position, color, size, and movement behavior. Rectangle inherits from Shape and draws a rectangle; Square inherits from Rectangle and passes equal dimensions to the parent initializer; Circle inherits from Shape and replaces drawing behavior for circular geometry. section 4.1.3

class ParentClass:
    pass
 
class ChildClass(ParentClass):
    pass

Shows the minimal Python syntax for declaring a parent class and inheriting from it. section 4.1.3

How The Well-Grounded Python Developer: How the pros use Python and Flask covers it

How deep it goes
Explains parent-child terminology, inheritance syntax, specialization, and parent initialization through shape examples.
Examples
Uses ParentClass and ChildClass, then develops Shape, Rectangle, Square, and Circle drawing classes.
What it assumes
Assumes familiarity with classes and objects while teaching parent, child, base, derived, superclass, and subclass terminology.
What you can do after
Build inheritance relationships and reuse or specialize parent behavior in Python classes.
How it connects
Connects inheritance with subclasses, derived classes, class design, polymorphic shape behavior, and the DRY principle.

Also explained in

Compare how 10 books explain superclass →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Python Developer: How the pros use Python and Flask. The section links point to the parts of the book it draws on.