Skip to content

Latest commit

 

History

History
35 lines (28 loc) · 1.79 KB

File metadata and controls

35 lines (28 loc) · 1.79 KB

Factory Method — where it lives outside this repo

Cited, real implementations to study (or point an agent at) when designing or reviewing factory-slot code.

Python standard library

  • http.client.HTTPConnection.response_class. The canonical class-attribute factory: the connection builds its response objects through the attribute, so a one-line subclass swaps in a custom response type. docs.python.org/3/library/http.client.html
  • json.JSONDecoder(object_hook=..., parse_float=...). Instance-attribute factories: each decoder instance carries the callables it will use to build numbers and objects. docs.python.org/3/library/json.html
  • asyncio.loop.set_task_factory. A pluggable creation hook on the event loop — the factory is set at runtime, not baked into a subclass. docs.python.org/3/library/asyncio-eventloop.html

Major ecosystems

What to notice across all of them

None of these ship an abstract factory_method() — every one is an attribute holding a callable. The variation point is data on the class, which is why overriding takes one line and why tests can substitute doubles without touching a hierarchy.