Are there only 23 design patterns?

Free Coding Questions Catalog
Boost your coding skills with our essential coding questions catalog. Take a step towards a better tech career now!

No, there aren’t just 23 design patterns, although the 23 "Gang of Four" (GoF) design patterns are the most well-known and foundational. These patterns were cataloged by the authors of the influential book "Design Patterns: Elements of Reusable Object-Oriented Software" (1994) and include classic creational, structural, and behavioral patterns. However, many more patterns have been identified and used in software engineering since then.

Here’s an overview of how design patterns have expanded beyond the original 23:

1. Enterprise and Architectural Patterns

As systems have grown more complex, particularly in enterprise environments, new patterns have been developed to address large-scale and distributed architecture needs. Some examples include:

  • MVC (Model-View-Controller): Separates an application into three interconnected components.
  • MVVM (Model-View-ViewModel): Common in frontend frameworks like Angular and React.
  • Microservices: A design approach where applications are structured as a collection of loosely coupled services.
  • Event Sourcing: Captures changes to an application’s state as a series of events. These patterns support scalable and maintainable enterprise applications.

2. Concurrency and Multithreading Patterns

With the rise of multi-core processors and distributed systems, patterns for handling concurrent tasks and parallel processing are more relevant than ever. Some examples are:

  • Producer-Consumer: Decouples the production of data from its consumption, often used with queues.
  • Singleton (Thread-Safe Variant): A variation of the Singleton pattern for safe use in concurrent environments.
  • Reactor and Proactor: Handle multiple service requests in a non-blocking, asynchronous way, often used in networked systems. These patterns help ensure efficient and safe handling of multiple threads and processes.

3. Functional Programming Patterns

Functional programming has popularized patterns that are focused on immutability, function composition, and declarative programming. Examples include:

  • Monad: A pattern that encapsulates computations in context, commonly used in languages like Haskell and Scala.
  • Memoization: Caches results of function calls to avoid repeated computation.
  • Currying: Transforms a function that takes multiple arguments into a sequence of functions, each taking a single argument. Functional patterns are particularly useful for applications where pure functions and immutability are emphasized.

4. Cloud and Distributed System Patterns

With cloud computing and distributed architectures, new patterns address concerns like scalability, fault tolerance, and efficiency in distributed environments. Some examples are:

  • Circuit Breaker: Prevents a system from continuously trying to execute a failing operation.
  • Service Discovery: Helps services in a microservices architecture find each other.
  • Sidecar: Deploys a helper container alongside an application container to provide capabilities such as logging or network monitoring. These patterns support the robust design of cloud-native and distributed applications.

5. User Interface (UI) Patterns

UI/UX development has led to the creation of patterns that enhance user experience and improve code maintainability for front-end applications. Examples include:

  • Presenter: Separates logic from the UI, similar to MVC and MVVM.
  • Command Pattern for UI: Used for UI components where actions are encapsulated as objects.
  • State Pattern for Forms: Manages complex form interactions based on user inputs. These patterns enhance the maintainability and reusability of UI code.

6. Behavioral and Micro-Interaction Patterns

With modern user experience (UX) demands, new patterns focus on user engagement and smooth functionality in interactive applications. Some examples are:

  • Feedback Loop Pattern: Ensures user actions are immediately reflected visually (e.g., loading indicators).
  • Undo Pattern: Allows users to reverse actions, commonly implemented with the Command pattern.
  • Infinite Scroll: Loads content dynamically as a user scrolls, frequently seen in web applications. These patterns are crucial for designing highly interactive and responsive user experiences.

7. Game Development Patterns

In game development, specialized patterns handle complex object interactions, state management, and efficient rendering. Examples include:

  • Game Loop: Manages the continuous updating and rendering cycle in games.
  • Entity-Component-System (ECS): A pattern for organizing game objects with a focus on data-oriented design.
  • Object Pooling: Reuses objects to avoid the overhead of frequently creating and destroying them. These patterns help optimize performance and structure complex game interactions.

8. Domain-Driven Design (DDD) Patterns

Domain-Driven Design (DDD) introduces patterns for structuring code around complex business domains, particularly in enterprise and large-scale systems. Some DDD patterns include:

  • Aggregate: Encapsulates multiple entities into a single unit for consistency.
  • Repository: Provides a mechanism to access data, allowing separation between domain and data access logic.
  • Service Layer: Defines application-specific logic for business processes, separate from core domain logic. DDD patterns are invaluable in applications where complex business rules and data models need clear structuring.

9. Anti-Patterns

Anti-patterns are solutions that may initially seem appropriate but lead to poor design and problems in the long term. Recognizing these is important to avoid common pitfalls. Examples include:

  • God Object: A single object that knows too much or does too much, making the code harder to maintain.
  • Spaghetti Code: Unstructured and tangled code that’s difficult to read, understand, and maintain.
  • Golden Hammer: Overuse of a familiar tool or pattern even when it’s not the best fit for the problem. Understanding anti-patterns helps in identifying and avoiding inefficient or problematic design choices.

Conclusion

While the GoF patterns (23) form the foundation of design patterns in software engineering, the field has expanded with patterns tailored to specialized domains such as enterprise systems, concurrency, functional programming, cloud computing, and game development. These newer patterns address the evolving challenges in software design, ensuring that systems are efficient, scalable, and maintainable in modern contexts. As a software engineer, being familiar with both foundational and newer patterns will help you apply best practices to a wide range of software development problems.

TAGS
System Design Interview
CONTRIBUTOR
Design Gurus Team

GET YOUR FREE

Coding Questions Catalog

Design Gurus Newsletter - Latest from our Blog
Boost your coding skills with our essential coding questions catalog.
Take a step towards a better tech career now!
Explore Answers
What are the best strategies for interviewing?
Why should we hire you as a frontend developer?
How to describe yourself in mock interview?
Related Courses
Image
Grokking the Coding Interview: Patterns for Coding Questions
Image
Grokking Data Structures & Algorithms for Coding Interviews
Image
Grokking Advanced Coding Patterns for Interviews
Image
One-Stop Portal For Tech Interviews.
Copyright © 2024 Designgurus, Inc. All rights reserved.