Hasty Briefsbeta

Bilingual

Design Patterns

a day ago
  • Design patterns are common solutions to recurring problems in software design, meant to be used naturally rather than forced.
  • The Strategy pattern encapsulates behavior via functions or objects, useful for clean code and deduplication.
  • The Factory pattern creates objects, encapsulating state or hiding construction logic.
  • The Visitor pattern is the inverse of an iterator, useful for trees/graphs but less ergonomic than iterators.
  • The Builder pattern constructs objects with many configurable fields, primarily useful in libraries for non-breaking API changes.
  • The Singleton pattern ensures only one instance of a class exists (e.g., loggers, thread pools), but harms testability.
  • Other patterns like Facade and Command are considered trivial and intuitive, not worth special discussion.
  • Explicitly naming patterns (e.g., FooBuilder, visit) helps communicate intent in code.