Google Developers Day US
Python Design Patterns
Facade forces and what counts as a pattern
0:00-
1In this talk, what two forces make a rich subsystem painful for both client authors and subsystem maintainers?Clients must confront unbridled complexity; maintainers cannot change exposed APIs without breaking clients.
Your note
-
2What does the Facade pattern interpose between clients and a complex subsystem?A simple object or class that exposes only the subset of functionality clients need and delegates internally to the subsystem.
Your note
-
3According to the speaker, what four ingredients does a design pattern summary include?A frequent design problem, a solution structure with pros/cons and alternatives, and a name for shared vocabulary.
Your note
GoF families and Python composition idioms
7:14-
1How does the Gang of Four taxonomy divide patterns into three families?Creational (instantiation), structural (composition), behavioral (interaction and responsibility distribution).
Your note
-
2Why does the speaker treat duck typing and object composition as prerequisites before naming patterns?Program to an interface (duck typing) and favor object composition over class inheritance (hold/wrap idioms).
Your note
Composition and creational patterns
10:00-
1Hold vs wrap: which exposes internal structure to clients and which keeps coupling thin via delegation?Hold couples clients to the held sub-object (
o.s.method). Wrap hides the wrappee and delegates so clients see onlyo.method.Your note
-
2Why does calling
Fu()in Python already resemble a factory without a separate pattern?IfFuis a class it constructs; ifFubecomes a callable function, callers need not change—flexibility withoutnewsyntax.Your note
-
3Why does the speaker rename Singleton "Highlander," and what inheritance conflict does he describe?"There can be only one" instance; subclassing breaks when a
Barsubclass of singletonFoomust also be that sameFooinstance.Your note
-
4How does the Borg (Monostate) pattern share state across many instances in Python?Replace each instance's
__dict__with a class-level shared dict so identity differs but mutations are visible everywhere.Your note
Dependency injection and structural adapters
20:00-
1Why does the speaker say passing dependencies in from outside makes testing easier?Don't construct dependents inside a class—pass them in from outside—so tests can substitute fakes more easily.
Your note
-
2Adapter vs Facade: what is each primarily about?Adapter tweaks or translates an interface (often one object). Facade simplifies an overly rich subsystem to a needed subset (often many classes).
Your note
-
3In the toy adapter example, how does a wrapper turn required
foo_bar(foo, bar)into supplierbar_foo(bar, foo)?Hold the supplier in an attribute and implementfoo_barby callingbar_foowith arguments swapped.Your note
-
4When is a mixin-style adapter class meant to be used instead of instantiated alone?Multiply inherit it with the class that supplies the mismatched method so one adaptation serves many concrete types.
Your note
Self-delegation and hook methods
28:12-
1Why does the speaker prefer "self-delegation" over "Template Method"?"Template" is overloaded (C++, HTML, etc.); self-delegation describes a base-class facet delegating hook work to a subclass facet of the same object.
Your note
-
2In the Template Method / self-delegation structure, what roles do the organizing method and hook methods play?The organizing method in the base class runs the workflow; hook methods in concrete subclasses supply variable steps.
Your note
-
3In
cmd.Cmd, what doescmdloopexemplify about frameworks?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).Your note
-
4In
queue.Queue.put, why is_puta hook whileputis the organizing method?puthandles synchronization and waiting;_putonly appends to the internal deque—so you can change queuing discipline without reimplementing thread safety.Your note
Q&A: patterns in Python
40:00-
1In Q&A, does the speaker claim any GoF pattern is especially bad in Python?No—patterns are typically not needed rather than harmful; mixin/multiple-inheritance patterns work in Python unlike Smalltalk's warning.
Your note