CodeRigor

FREE COURSE / REAL PRACTICE

Practical Python classes & composition

Design small Python programs with real classes, explicit ownership, stable interfaces and dependable failure behavior.

Free lessons & exercises7 authored lessons2 units

What you’ll work toward

Build and test a single-threaded in-memory inventory with validated entities, immutable receipts, polymorphic collaborators and all-or-nothing reservations.

Read an explanation, inspect the diagrams and work through the available checks, debugging exercises and builds. Feedback and prerequisite links guide the next step.

Before you start

This course builds on these skills:

Individual lessons can add prerequisites. The course map shows your actual readiness.

A look inside the first lesson

Classes, instances & owned state

Python
class Shelf:
    kind = "shelf"

    def __init__(self, name, items=()):
        self.name = name
        self._items = list(items)

    def add(self, item):
        self._items.append(item)

    def snapshot(self):
        return tuple(self._items)

front = Shelf("front", ["map"])
back = Shelf("back")
front.add("pen")
Shelf.add(back, "ticket")
print(front.name, front.snapshot())
print(back.name, back.snapshot())
print(Shelf.kind)

Your course outline

Follow the lessons in curriculum order. Open a unit to preview the ideas you’ll work with.

UNIT 014 lessons Objects with responsibilities
  1. LESSON 01.01

    Classes, instances & owned state

    Define real Python classes with per-instance attributes, bound methods and explicit ownership of mutable state.

    Open lesson
  2. LESSON 01.02

    Initialization, properties & invariants

    Construct valid objects and preserve nonnegative stock through checked methods and read-only properties.

    Open lesson
  3. LESSON 01.03

    Methods as state transitions

    Design commands and queries around a bounded reservation state machine, with explicit errors and no partial updates.

    Open lesson
  4. LESSON 01.04

    Composition & collaborator ownership

    Compose an Order with a shared Catalog while keeping each order’s mutable quantities independent.

    Open lesson
UNIT 023 lessons Interfaces, values & an integrated inventory
  1. LESSON 02.01

    Interfaces, polymorphism & justified inheritance

    Program to a small pricing protocol and use inheritance only when a subclass preserves the same callable contract.

    Open lesson
  2. LESSON 02.02

    Value objects, equality & replacement

    Design immutable priced-line values with generated equality/hash behavior, validated replacement and price-aware aggregation.

    Open lesson
  3. LESSON 02.03

    Capstone: atomic inventory reservations

    Integrate validated mutable entities, immutable receipts and composition in an all-or-nothing in-memory inventory.

    Open lesson