liveBook · Manning

Don't repeat yourself principle

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

The DRY principle is the software design principle of avoiding duplicated knowledge or logic in a codebase.

DRY means avoiding repeated knowledge or logic. Repetition creates opportunities for mistakes and inconsistencies: a correction may reach one copy but not another. section 4.1.3

In Python object-oriented design, inheritance applies DRY by placing shared attributes and behavior in a parent class. Child classes inherit that foundation while adding or modifying specialized behavior. section 4.1.3

Sharing shape behavior

A Shape class can provide common state, while Rectangle, Square, and Circle reuse that structure and implement their own drawing details. Square delegates shared initialization to Rectangle with super(). section 4.1.3

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

How deep it goes
Explains duplication's maintenance risk and demonstrates inheritance through a growing shape-class hierarchy.
Examples
Uses Shape, Rectangle, Square, and Circle examples, including shared initialization and specialized drawing behavior.
What it assumes
Builds on Python classes while defining parent, child, base class, derived class, superclass, and subclass terminology.
What you can do after
Apply it via inheritance to share common attributes and behavior while specializing child classes.
How it connects
Connects DRY with inheritance, classes, parent classes, child classes, and object-oriented design.

Also explained in

Compare how 10 books explain don't repeat yourself principle →

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.