Design patterns with Python

A design pattern is a name for a solution you have probably already half-written. We go through the main ones, adapted to Python rather than copied from Java, see those built into the language, then combine them to solve real problems.

Duration: 3 days · Level: advanced

For: experienced Python developers who want to master design patterns.

Prerequisites: a good command of Python and object-oriented programming.

Design patterns with Python

Day 1 — Building blocks

  • What is a design pattern, when to use one, who benefits?
  • Picking an algorithm on the fly with dependency injection
  • Making code on the fly with factory and abstract factory
  • Imitating jQuery with the chaining pattern
  • Getting organised with the registry pattern
  • Abstract classes and the template pattern
  • Proxy objects
  • Composition VS inheritance
  • Strategy: composition with dependency injection
  • State: changing your strategy on the fly
  • Hiding a complex system behind a facade
  • Square pegs in round holes with the adapter pattern
  • The decorator pattern, the pool and the lazy pattern

Day 2 — Dispatching, the Python way

  • Stacking operations and applying them with command
  • Loose coupling and pluggability with observer
  • Spreading information to subscribers with pub/sub
  • Middlewares with chain of responsibility
  • Built into the language: iterator, and how it compares with visitor
  • Built into the language: generator, and its link with facade
  • Built into the language: the context manager
  • Getters and setters: not so useful in Python
  • Duck typing: dunder methods, operators and protocols
  • Intercepting method calls
  • Borg, caching, flyweight and modules instead of the singleton

Day 3 — Advanced cases

  • The art of doing nothing: identity, null and mock
  • Knowing where you are with the state machine pattern
  • Combining patterns: observer and decorator
  • Combining patterns: strategy and factory
  • Combining patterns: chaining and factory
  • Combining patterns: state machine and observer
  • Registry + dependency injection = inversion of control
  • The biggest pattern of all: MVC

Elevate Your Python Proficiency!