Skip to content
IT glossary
ProgrammingUpdated December 3, 2026

Design patterns

Паттерны проектирования

Design patterns are reusable ways to organize code around common problems. For example, a pattern can show you how to add new pricing rules without rewriting the checkout logic.

Also known as: шаблоны проектирования

What a design pattern gives you

Imagine a reporting tool that exports CSV today and needs JSON next month. You could put both formats in one function and branch on the file type, or you could give each format its own exporter and let the reporting code call whichever one it receives. A design pattern describes the second kind of decision: what each part is responsible for and how the parts fit together. It is not a snippet you copy into a project.

Pattern names also give teams a shared vocabulary. Saying “this is an adapter” tells a reviewer to look for code that bridges two interfaces. It doesn't tell them whether the adapter is a function, a class, or a module. That depends on the language and the codebase.

Three families in the classic catalog

The Gang of Four (GoF) catalog groups its object-oriented design patterns by purpose:

  • Creational patterns deal with how objects are created. Builder, for example, assembles an object step by step.
  • Structural patterns deal with how parts fit together. Adapter lets existing code work with a component whose interface doesn't match what the caller expects.
  • Behavioral patterns deal with how parts cooperate. Strategy makes an operation replaceable, while Observer lets registered listeners react to an event.

That taxonomy describes the GoF catalog, not every pattern used in software design. An architectural pattern such as MVC addresses a broader division of responsibilities than a local pattern such as Adapter.

Example: adapt an existing interface

Suppose a report writer calls logger.info(message), but a library you need to use only offers log(level, message). Instead of changing every call site, translate at the boundary:

class LoggerAdapter:
    def __init__(self, library_logger):
        self.library_logger = library_logger

    def info(self, message):
        self.library_logger.log('INFO', message)

Pass a LoggerAdapter to the report writer in place of its usual logger. The writer still calls info; only the adapter knows how the library represents a log level. This adapter implements just the operation the writer needs. If callers also need warning, the adapter must support that too.

When a pattern earns its place

Use a pattern when it solves a problem you can point to. An adapter is useful if several callers already share an interface and you want to keep library-specific details out of them. If there is only one call site and no interface to preserve, calling the library directly may be easier to read. Likewise, a two-branch conditional isn't a failed Strategy implementation: it may be the clearest way to express two stable cases.

How it comes up in interviews

An interviewer may ask how you'd add another export format or swap out a third-party library. Start by identifying what changes and what should stay stable. Then show how you'd split the responsibilities, where the implementation gets selected, and what extra code your approach requires. A familiar pattern name helps explain the design, but doesn't justify it on its own.