Source: https://mokxi.com/teachers/plans/python-oop-in-depth
Updated: 2026-11-19

Lesson plan

# Objects in depth lesson plan

Object-oriented Python past the basics, on a Raspberry Pi: class and instance attributes, inheritance and super(), composition, dunder methods, properties, dataclasses and enum, ending with a device library for a starship.

4 chapters, 7 lessons, about 5 hours, on the Raspberry Pi 4 Model B. Every lesson runs in the browser, with nothing to install.

Start a class from this course

The unit

## Objectives and materials

### By the end, students can

- What a class really is, and how classes inherit from each other.
- Objects built from objects, and objects that act like Python's own types.
- Properties that guard the hardware, dataclasses and enums that cut the boilerplate.
- A device class library for the starship Kestrel.

### Materials for the whole unit

- Half breadboard
- Hobby servo
- LED x 2
- Pushbutton
- Raspberry Pi 4 Model B
- Resistor x 2
- Traffic light module

Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.

Chapter 1. About 1 h 20 min

## Classes and families

What a class really is, and how classes inherit from each other.

Lesson | Time | What students do

Classes revisited Look again at the class you think you know, on the starship Kestrel's lamps: what self really is, the shared-list bug that class attributes cause, the right use for them, classmethods as second constructors, and bound methods. | 40 min

- Run it: the Kestrel's lamps
- The shared list bug
- Per object, per class
- A classmethod constructor
- Bound methods

Inheritance Give the Kestrel's bridge lights a family tree: a Device base class, subclasses that override and extend with super(), one loop that drives any device (polymorphism), and an abstract base class that refuses a subclass missing its methods. | 40 min

- Run it: a family of devices
- Override: a blinking lamp
- Extend with super()
- One loop, any device
- An abstract base class

### Materials

- Half breadboard
- LED x 2
- Pushbutton
- Raspberry Pi 4 Model B
- Resistor x 2
- Traffic light module

### Check for understanding

Each student finishes "Inheritance" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "An abstract base class".

Chapter 2. About 1 h 20 min

## Parts and protocols

Objects built from objects, and objects that act like Python's own types.

Lesson | Time | What students do

Composition Build the Kestrel's bridge panel out of parts instead of a family tree: a panel that has lamps, modes as data, lamps handed in from outside so a fake can stand in for testing, and a button wired to a bound method. | 30 min

- Run it: a panel that has lamps
- Modes as data
- Hand the parts in
- A button in the panel

Dunder methods Make the Kestrel's lamps act like Python's own types: __repr__ and __str__ for printing, __len__, __getitem__, __contains__ and __iter__ for a container, __lt__ and __bool__ for sorting and truth, __add__, and __enter__ and __exit__ for a with block. | 50 min

- Run it: an object that prints badly
- __repr__ and __str__
- A container
- Sorting and truth
- Adding to a bank
- A with block: the lights drill

### Materials

- Half breadboard
- LED x 2
- Pushbutton
- Raspberry Pi 4 Model B
- Resistor x 2
- Traffic light module

### Check for understanding

Each student finishes "Dunder methods" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "A with block: the lights drill".

Chapter 3. About 1 h 30 min

## Rules and records

Properties that guard the hardware, dataclasses and enums that cut the boilerplate.

Lesson | Time | What students do

Properties Guard the Kestrel's cargo hatch servo: see a plain attribute lie about where the hatch is, turn it into a property whose setter moves the servo and clamps bad angles, add a read-only computed property, and refuse moves while the hatch is locked. | 50 min

- Run it: the cargo hatch
- An attribute that lies
- A property that moves the servo
- Validation in the setter
- A read-only property
- A safety interlock

dataclasses and enum Let Python write the boring parts: a dataclass in place of hand-written __init__, __repr__ and __eq__, frozen records that cannot be changed by accident, an Enum whose typos fail loudly, and the plain-class constants pattern for boards with no enum module. | 40 min

- Run it: boilerplate and a silent typo
- A dataclass
- Frozen records
- An Enum for the modes
- Constants without enum

### Materials

- Hobby servo
- Pushbutton
- Raspberry Pi 4 Model B
- Traffic light module

### Check for understanding

Each student finishes "dataclasses and enum" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Constants without enum".

Chapter 4. About 50 min

## Project

A device class library for the starship Kestrel.

Lesson | Time | What students do

Project: a device class library Put the course together as a real library: a kestrel.py module with Device, Lamp and Hatch classes, a Ship that composes them, a serial console that drives any device by name, and a new device type added without touching the code that uses it. | 50 min

- Run it: a library in its own module
- Add the hatch
- A ship that has devices
- A console for any device
- A new device, no other changes
- Your own device

### Materials

- Half breadboard
- Hobby servo
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2

### Check for understanding

Each student finishes "Project: a device class library" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Your own device".

Your class

## Teach this unit as a class

Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.

The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.

Start a class from this course See the demo class

More units

## Other lesson plans

Electronics basics 20 lessons, about 10 h. Embedded on the Arduino Uno 16 lessons, about 12 h. Embedded on the ESP32-C3 13 lessons, about 11 h. Embedded on the Raspberry Pi Pico 7 lessons, about 6 h. Build your own fight stick 5 lessons, about 4 h. Embedded on the STM32F411 6 lessons, about 6 h. C++ on a board 13 lessons, about 10 h. Digital logic and memory 4 lessons, about 4 h. Interactive devices on the Uno 9 lessons, about 8 h. From gates to a computer 23 lessons, about 16 h. Build a claw machine 8 lessons, about 6 h. Every unit All the courses as ready-made units, on the teachers page.
