Here’s a list of the most used and most common design patterns, categorized by their type and popularity in software development:
1. Creational Patterns
Focus on object creation mechanisms, providing flexibility and efficiency.
-
Ensures a class has only one instance and provides a global point of access to it.
Commonly used for logging, configuration, and managing shared resources.
-
Defines an interface for creating objects but lets subclasses decide which class to instantiate.
Commonly used in frameworks for creating objects without specifying exact classes.
-
Provides an interface to create families of related or dependent objects without specifying their concrete classes.
Used in GUI libraries (e.g., different themes for UI components).
Builder
Constructs complex objects step-by-step, separating the construction from representation.
Useful for creating immutable objects like
StringBuilder
or for object hierarchies.
Prototype
Creates new objects by cloning an existing object (prototypes).
Used when object creation is costly, e.g., in game engines or document editors.
2. Structural Patterns
Deal with composing classes or objects into larger structures while keeping them flexible and efficient.
Adapter
Allows incompatible interfaces to work together by translating one interface to another.
Commonly used in legacy system integrations.
Decorator
Adds functionality to an object dynamically without altering its structure.
Common in user interface components (e.g., adding scrollbars or borders).
Facade
Provides a simplified interface to a complex subsystem.
Often used in APIs and libraries to hide implementation details.
Composite
Composes objects into tree structures to represent part-whole hierarchies.
Frequently used in GUIs and file system representations.
Proxy
Provides a surrogate or placeholder for another object to control access to it.
Used for lazy initialization, access control, and logging.
Bridge
Decouples an abstraction from its implementation so that both can vary independently.
Common in graphical rendering libraries.
Flyweight
Reduces memory usage by sharing as much data as possible with similar objects.
Used in caching mechanisms or text editors for character storage.
3. Behavioral Patterns
Concerned with the communication and interaction between objects.
Strategy
Encapsulates algorithms and allows them to be interchangeable at runtime.
Common in payment processing systems and sorting algorithms.
Observer
Defines a dependency between objects so that when one changes state, its dependents are notified.
Commonly used in event-driven programming and GUIs.
Command
Encapsulates a request as an object, allowing parameterization and queuing of requests.
Used in undo/redo systems and job scheduling.
State
Allows an object to change its behavior when its state changes.
Frequently used in workflows or state machines.
Template Method
Defines the skeleton of an algorithm in a base class, allowing subclasses to override specific steps.
Common in frameworks and libraries.
Chain of Responsibility
Passes a request along a chain of handlers until it is handled.
Used in logging systems or middleware pipelines.
Mediator
Centralizes communication between objects to reduce dependencies.
Common in chat applications or GUIs.
Iterator
Provides a way to access elements of a collection sequentially without exposing its underlying structure.
Used in collections and data structures.
Visitor
Adds new operations to objects without modifying their classes.
Used in compilers or processing hierarchical structures.
Memento
Captures an object’s state to restore it later.
Commonly used in undo functionality.
Additional Modern Patterns
Beyond the classical Gang of Four patterns, these modern patterns are also widely used:
Dependency Injection (DI)
Provides dependencies to objects from an external source, improving modularity.
A cornerstone of frameworks like Spring or .NET Core.
Model-View-Controller (MVC)
Separates an application into three components: Model (data), View (UI), and Controller (logic).
Dominant in web development frameworks like Ruby on Rails and ASP.NET MVC.
Model-View-ViewModel (MVVM)
Variant of MVC, primarily used in UI frameworks like Angular or WPF.
Repository
Abstracts access to data sources, providing a clean separation between the application and data layer.
Common in DDD (Domain-Driven Design).
CQRS (Command Query Responsibility Segregation)
Separates read and write operations into different models.
Used in scalable architectures.
Event Sourcing
Represents the state of an object as a sequence of events.
Common in microservices and systems requiring strong audit trails.
Most Used Patterns in Practice
Singleton
Factory Method
Strategy
Observer
MVC/MVVM
Dependency Injection
Repository
Adapter
Decorator
Command
These patterns are versatile, widely applicable, and form the backbone of most modern software systems.
No hay comentarios.:
Publicar un comentario