All paths

Objects in depth

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.

Raspberry Pi 4 Model BFree7 lessons5 h4 chapters2,125 XPCoding · Intermediate+150 XP

0 of 7 done

What you will build

3 projects, built step by step

7 lessons in 4 chapters, about 5 hours on a simulated Raspberry Pi 4 Model B. Free, in your browser, every step checked by the simulator.

Chapter 1 project

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.

Open it in the simulator
Chapter 2 project

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.

Open it in the simulator
Chapter 3 project

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.

Open it in the simulator
The map

Chapter by chapter

Each lesson opens when the one before it is done, and each chapter ends in a project.

Chapter 1

Classes and families

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

  1. Open205 XP

    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.

    0 of 5 steps

  2. ProjectLocked410 XP

    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.

    0 of 5 steps

5 questions, graded as you go.
Chapter 2

Parts and protocols

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

  1. Locked174 XP

    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.

    0 of 4 steps

  2. ProjectLocked472 XP

    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.

    0 of 6 steps

5 questions, graded as you go.
Chapter 3

Rules and records

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

  1. Locked236 XP

    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.

    0 of 6 steps

  2. ProjectLocked410 XP

    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.

    0 of 5 steps

5 questions, graded as you go.
Chapter 4

Project

A device class library for the starship Kestrel.

  1. Locked218 XP

    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.

    0 of 6 steps

4 questions, graded as you go.
Syllabus

Every lesson in the course

All 7 lessons, in order, each with what it covers. Any of them opens in the editor right away.

Chapter 1

Classes and families

  1. Classes revisitedLook 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.
  2. InheritanceGive 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.
Chapter 2

Parts and protocols

  1. CompositionBuild 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.
  2. Dunder methodsMake 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.
Chapter 3

Rules and records

  1. PropertiesGuard 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.
  2. dataclasses and enumLet 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.
Chapter 4

Project

  1. Project: a device class libraryPut 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.
Kits

Build it on your bench too

Every lesson runs in the simulator with nothing to buy. When you want the real thing, these kits have the parts.

Have a kit already?

Find your kit

Pick the starter kit you own and run every lesson in its manual with the same parts on the same pins.

See every kit
Questions

About Objects in depth

Is Objects in depth free?

Yes. All 7 lessons of Objects in depth are free and run in your browser, with nothing to install and no parts to buy before you start.

Do I need a real Raspberry Pi 4 Model B?

No. Every lesson runs on a simulated Raspberry Pi 4 Model B with its parts on the canvas, and the simulator checks each step as you go. When you want to build it for real, the same wiring and code work on a real board.

How long does Objects in depth take?

About 5 hours: 7 lessons in 4 chapters, each one a few short steps. Your progress is kept, so you can stop after any lesson and pick up where you left off.

What will I build?

Each chapter ends in a project that puts it together: Inheritance, Dunder methods and dataclasses and enum.

Where do I start?

With "Classes revisited", and each lesson builds on the one before it. New to circuits? Electronics basics is the course that starts from zero.