NewWork mode: your Claude Code or Codex on work calls, answering from your project's codeSkip to content
Middle+1 view

Which design patterns have you used in real-world work, and in what situations?

Practice

Asked at

AI answer

I’ve used different patterns depending on the task:

  • Dependency Injection — to pass dependencies to services explicitly and simplify testing.
  • Repository — to separate business logic from data-storage details.
  • Strategy — when an operation needs to be performed in different ways, for example, choosing a calculation or payment method.
  • Factory — to centralize the creation of objects with different configurations.
  • Adapter — to adapt a third-party library’s interface to the application’s interface.
  • Observer / events — to trigger side effects, such as notifications, without coupling them directly to the main logic.

I try to use a pattern when it solves a specific problem, rather than adding abstractions for the sake of the pattern itself.