~/talk

Retiring the Singleton Pattern: Concrete Suggestions for What to use Instead

Talkat CppCon 2020 · 2020-09-14..09-18· [software-architecture, testing]
links:none on file
slides:none on file

Shows how to remove hidden singletons by introducing small wrapper types (e.g. comWrapper) passed as parameters with a default obtained via lazy factory like get_default_comms, turning opaque global access into constructor or parameter injection. Uses virtuals or std::function/std::ref to enable mocks, groups many dependencies in a service struct or with templates/type erasure, and preserves ABI by keeping single-parameter dispatchors that forward to two-parameter implementations. Implementation runs at Bloomberg, fixes copy/fork socket bugs, and makes formerly untestable code unit-testable.

AI-written summary · about

  1. 0:00Motivation for retiring
  2. 4:50Defining the problem
  3. 6:34Analyzing the singleton pattern
  4. 11:56Singleton or not: a quiz
  5. 15:05Refactoring with dependency injection
  6. 24:30Modern C++ approaches
  7. 32:11Preserving compatibility
  8. 34:03Initialization strategies
  9. 37:53Phased introduction
  10. 40:57Interdependent dependencies
  11. 47:10Grouping multiple dependencies
  12. 54:04Final conclusions and Q&A
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.