lunes, 2 de abril de 2018

Some of the most used and most common design patterns.

 

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.

  1. Singleton

    • 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.

  2. Factory Method

    • 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.

  3. Abstract Factory

    • 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).

  4. Builder

    • Constructs complex objects step-by-step, separating the construction from representation.

    • Useful for creating immutable objects like StringBuilder or for object hierarchies.

  5. 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.

  1. Adapter

    • Allows incompatible interfaces to work together by translating one interface to another.

    • Commonly used in legacy system integrations.

  2. Decorator

    • Adds functionality to an object dynamically without altering its structure.

    • Common in user interface components (e.g., adding scrollbars or borders).

  3. Facade

    • Provides a simplified interface to a complex subsystem.

    • Often used in APIs and libraries to hide implementation details.

  4. Composite

    • Composes objects into tree structures to represent part-whole hierarchies.

    • Frequently used in GUIs and file system representations.

  5. Proxy

    • Provides a surrogate or placeholder for another object to control access to it.

    • Used for lazy initialization, access control, and logging.

  6. Bridge

    • Decouples an abstraction from its implementation so that both can vary independently.

    • Common in graphical rendering libraries.

  7. 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.

  1. Strategy

    • Encapsulates algorithms and allows them to be interchangeable at runtime.

    • Common in payment processing systems and sorting algorithms.

  2. Observer

    • Defines a dependency between objects so that when one changes state, its dependents are notified.

    • Commonly used in event-driven programming and GUIs.

  3. Command

    • Encapsulates a request as an object, allowing parameterization and queuing of requests.

    • Used in undo/redo systems and job scheduling.

  4. State

    • Allows an object to change its behavior when its state changes.

    • Frequently used in workflows or state machines.

  5. Template Method

    • Defines the skeleton of an algorithm in a base class, allowing subclasses to override specific steps.

    • Common in frameworks and libraries.

  6. Chain of Responsibility

    • Passes a request along a chain of handlers until it is handled.

    • Used in logging systems or middleware pipelines.

  7. Mediator

    • Centralizes communication between objects to reduce dependencies.

    • Common in chat applications or GUIs.

  8. Iterator

    • Provides a way to access elements of a collection sequentially without exposing its underlying structure.

    • Used in collections and data structures.

  9. Visitor

    • Adds new operations to objects without modifying their classes.

    • Used in compilers or processing hierarchical structures.

  10. 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:

  1. Dependency Injection (DI)

    • Provides dependencies to objects from an external source, improving modularity.

    • A cornerstone of frameworks like Spring or .NET Core.

  2. 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.

  3. Model-View-ViewModel (MVVM)

    • Variant of MVC, primarily used in UI frameworks like Angular or WPF.

  4. Repository

    • Abstracts access to data sources, providing a clean separation between the application and data layer.

    • Common in DDD (Domain-Driven Design).

  5. CQRS (Command Query Responsibility Segregation)

    • Separates read and write operations into different models.

    • Used in scalable architectures.

  6. 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

  1. Singleton

  2. Factory Method

  3. Strategy

  4. Observer

  5. MVC/MVVM

  6. Dependency Injection

  7. Repository

  8. Adapter

  9. Decorator

  10. Command

These patterns are versatile, widely applicable, and form the backbone of most modern software systems.