Saltar al contenido ForoHackers

Design patterns: start here

Patrones de diseño
#839 · Ophuscado · · Denunciar

A design pattern is a named, reusable solution to a problem that keeps coming back in software design, with its context and its costs. Patterns are not code to paste: they are a shared vocabulary that lets a team say "use an observer here" and be understood, and they show up whenever objects or functions must cooperate.

Key concepts

  • Problem, solution, consequences: a pattern is only a pattern when you know when not to use it.
  • Creational patterns: factory, builder and singleton control how objects get made.
  • Structural patterns: adapter, decorator, facade and composite shape how objects fit together.
  • Behavioural patterns: strategy, observer, command, iterator and state shape how objects share work.
  • Principles underneath: program to interfaces, prefer composition to inheritance, keep one responsibility per unit.

Vocabulary

  • Gang of Four: the authors of the classic catalogue of object-oriented patterns.
  • Anti-pattern: a common response to a problem that makes things worse.
  • Dependency injection: passing a part its collaborators instead of letting it create them.
  • SOLID: five object-oriented design principles, from single responsibility to dependency inversion.

What to study, in order

  1. Write a small program with long if chains, then replace them with a strategy.
  2. Implement observer and iterator by hand in your main language.
  3. See which patterns your language makes unnecessary, such as functions as values replacing command.
  4. Read a mature codebase and name the patterns you find.
  5. Refactor one pattern you overused back to plain code.

Related tags

#architecture #refactoring #functional-programming #language-design

Inicia sesión o únete para responder.