Design Patterns in Python#

Welcome! This course covers the 18 design patterns you’ll meet most often in real Python code, one session each. Every session starts from code without the pattern, shows the problem, then fixes it with the pattern, and ends with an example from AI apps (LLMs, RAG and agents).

Note

What is a design pattern, in one line? A well-known, named solution to a problem that keeps coming back in software, like “only one of these may exist” or “add a feature without editing the class”. Knowing the name lets you spot the problem faster and explain your design in one word.

The three families of design patterns Creational patterns are about making objects, structural about fitting them together, behavioural about how they talk and share work. CREATIONAL How objects are made 1 Singleton 2 Factory Method 3 Abstract Factory 4 Builder 5 Prototype STRUCTURAL How objects fit together 6 Adapter 7 Decorator 8 Facade 9 Proxy 10 Composite 11 Bridge 12 Flyweight BEHAVIOURAL How objects work together 13 Strategy 14 Observer 15 Command 16 State 17 Template Method 18 Chain of Resp.
Creational patterns are about making objects, structural about fitting them together, behavioural about how they talk and share work.

How each session works#

  1. The big idea: the problem in plain words, with an everyday example.

  2. Without the pattern: code that works but hurts as it grows.

  3. With the pattern: the same job, done cleanly, with a diagram.

  4. The pattern + AI: where it shows up in LLM, RAG and agent code.

  5. Common mistakes and hands-on exercises, with solutions you can reveal.

  6. Practice: a quiz and a flashcard deck for the session.

Tip

New here? Do Setup first. Patterns at a glance compares all 18 side by side and ends with a “which pattern fits?” quiz. Try it after you finish each family.

Important

Don’t force patterns. Every pattern adds a little structure. Use one when you feel the pain it fixes (the same if/elif in five places, a class that keeps growing), not just because it has a name. Each session’s Common mistakes tells you when not to use it.

Getting started