Using Grok to Walk Like a Duck
summary
Adapters replace fragile subclassing, mixins and monkey‑patching by wrapping objects without changing them; Grok/zope.component implements this with three concrete steps: define an interface, register an adapter, request adaptation by calling the interface like a function. Example adapts email.message objects into tree nodes so unit tests use cheap mock messages, avoids factory and name‑collision problems, and runs in real apps; autoconfiguration can register adapters from conventions and the supplied example code works.
AI-written summary · about
chapters (16)
- 0:00Introduction
- 1:01Static vs dynamic typing
- 2:26Duck typing and email
- 4:13Subclassing flaws
- 8:27Mixins limitations
- 10:38Monkey patching drawbacks
- 13:10Adapters pattern
- 16:55Scattered adaptation logic
- 18:22Interfaces and Zope Component Architecture
- 21:19Adapter tips
- 24:52Grok auto-configuration
- 25:33Why Grok powerful
- 26:39Dynamic adaptation
- 27:47Adapters as two-story attribute names
- 28:08Future of adapters
- 29:12Q&A
related talks
31mHear no evil, see no evil, patch no evil: Or, how to monkey-patch safely.
27mBoring Object Orientation
57mThe Art of Subclassing
24m"A Confession of My Python Sins"
19mPatterns for Extensibility
29mDesign at scale with Web Components (and ducks)
57mArchetypes: this thing is good!™
30mAbstract tricks: how abstract base classes can help you to solve difficult challenges.
