Saltar al contenido ForoHackers

Design patterns: start here

Patrones de diseño
#3345 · · Citar · 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

No has iniciado sesión, así que esto se publica como anónimo: no se guarda con ello ninguna cuenta, nombre ni dirección, y no puede llevar enlaces ni imágenes. Inicia sesión o únete para publicar con tu nombre. Los registros de nuestro servidor web guardan la dirección y la hora de cada petición hasta 14 días; para que la tuya no quede en ellos, usa Tor. Para escribir al equipo de forma confidencial, usa el buzón. Firmar como fuente habitual (una clave guardada solo en este navegador)

Enviar tarda unos segundos aquí: tu navegador resuelve antes una prueba de trabajo contra el spam.

Responder