liveBook · Manning

Abstract class

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

An abstract class is a class intended to define shared structure or behavior without being instantiated directly.

An abstract class defines shared structure or behavior for related classes without being instantiated directly. It helps keep common code in one place instead of repeating it across each child class. section 4.1.3

class ParentClass:
    pass
 
class ChildClass(ParentClass):
    pass

A parent class can hold common characteristics while child classes inherit and extend them. section 4.1.3

A practical shape hierarchy starts with shared behavior in Shape, then specializes it through Rectangle and Circle. Rectangle can reuse inherited position and color data while providing its own drawing behavior; Circle can adapt inherited dimensions and override drawing for circular geometry. section 4.1.3

Use an abstract class when related classes should share a foundation but still provide their own details:

  • Centralize repeated attributes and behavior in the parent class. section 4.1.3
  • Let child classes add unique attributes or modify inherited behavior. section 4.1.3
  • Call inherited initialization with super() when constructing specialized objects. section 4.1.3

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

How deep it goes
Explains inheritance relationships and progressive shape examples, but does not detail abstract-class enforcement mechanisms.
Examples
Uses ParentClass and ChildClass listings, then develops Shape, Rectangle, Square, and Circle drawing classes.
What it assumes
Assumes familiarity with classes and object-oriented design while reinforcing parent-child inheritance terminology.
What you can do after
Apply it via Python inheritance to organize shared attributes and behavior across related classes.
How it connects
Connects abstract classes with inheritance, parent classes, child classes, overriding, DRY, and object-oriented class design.

Also explained in

Compare how 6 books explain abstract class →

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.