← Home

Google Developers Day US

Python Design Patterns

NOV 2026 · 18 cards

Review

Anki deck Markdown Episode

Facade forces and what counts as a pattern

0:00
  1. Clients must confront unbridled complexity; maintainers cannot change exposed APIs without breaking clients.
    1:08
  2. A simple object or class that exposes only the subset of functionality clients need and delegates internally to the subsystem.
    2:08
  3. A frequent design problem, a solution structure with pros/cons and alternatives, and a name for shared vocabulary.
    3:08

GoF families and Python composition idioms

7:14
  1. Creational (instantiation), structural (composition), behavioral (interaction and responsibility distribution).
    7:14
  2. Program to an interface (duck typing) and favor object composition over class inheritance (hold/wrap idioms).
    8:16

Composition and creational patterns

10:00
  1. Hold couples clients to the held sub-object (o.s.method). Wrap hides the wrappee and delegates so clients see only o.method.
    11:05
  2. If Fu is a class it constructs; if Fu becomes a callable function, callers need not change—flexibility without new syntax.
    14:11
  3. "There can be only one" instance; subclassing breaks when a Bar subclass of singleton Foo must also be that same Foo instance.
    17:14
  4. Replace each instance's __dict__ with a class-level shared dict so identity differs but mutations are visible everywhere.
    18:15

Dependency injection and structural adapters

20:00
  1. Don't construct dependents inside a class—pass them in from outside—so tests can substitute fakes more easily.
    20:01
  2. Adapter tweaks or translates an interface (often one object). Facade simplifies an overly rich subsystem to a needed subset (often many classes).
    27:08
  3. Hold the supplier in an attribute and implement foo_bar by calling bar_foo with arguments swapped.
    23:05
  4. Multiply inherit it with the class that supplies the mismatched method so one adaptation serves many concrete types.
    24:06

Self-delegation and hook methods

28:12
  1. "Template" is overloaded (C++, HTML, etc.); self-delegation describes a base-class facet delegating hook work to a subclass facet of the same object.
    28:12
  2. The organizing method in the base class runs the workflow; hook methods in concrete subclasses supply variable steps.
    30:01
  3. It is the organizing logic (input → precmd → command → postcmd) while subclasses supply concrete hooks—the "Hollywood principle" (don't call us, we'll call you).
    32:04
  4. put handles synchronization and waiting; _put only appends to the internal deque—so you can change queuing discipline without reimplementing thread safety.
    36:09

Q&A: patterns in Python

40:00
  1. No—patterns are typically not needed rather than harmful; mixin/multiple-inheritance patterns work in Python unlike Smalltalk's warning.
    41:01