Skip to content

LasithaPrabodha/design-patterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

Design Patterns

Design patterns in software engineering are reusable solutions to commonly occurring problems in software design. They provide proven approaches and best practices for structuring, organizing, and solving specific design problems. Design patterns help improve the quality, flexibility, and maintainability of software systems.

The 23 Gang of Four (GoF) patterns are generally considered the foundation for all other patterns. They are categorized in three groups: Creational, Structural, and Behavioral (for a complete list see below). This reference provides source code for each of the 23 GoF patterns.

  1. Creational Patterns:

    • Singleton: Ensures that a class has only one instance and provides a global point of access to it.
    • Factory Method: Defines an interface for creating objects, but lets subclasses decide which class to instantiate.
    • Abstract Factory: Provides an interface for creating families of related or dependent objects.
    • Builder: Separates the construction of complex objects from their representation, allowing the same construction process to create various representations.
    • Prototype: Creates new objects by cloning existing ones, avoiding the need for explicit instantiation.
  2. Structural Patterns:

    • Adapter: Converts the interface of a class into another interface that clients expect.
    • Decorator: Dynamically adds responsibilities to an object without modifying its structure.
    • Proxy: Provides a surrogate or placeholder for another object to control access to it.
    • Composite: Composes objects into a tree structure to represent part-whole hierarchies.
    • Bridge: Separates an abstraction from its implementation, allowing them to vary independently.
    • Facade: Provides a simplified interface to a complex subsystem, making it easier to use.
    • Flyweight: Aims to minimize the memory usage and improve performance by sharing objects with similar or identical state across multiple contexts.
  3. Behavioral Patterns:

    • Observer: Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
    • Strategy: Encapsulates interchangeable algorithms within a family and makes them interchangeable.
    • Command: Encapsulates a request as an object, thereby letting you parameterize clients with queues, requests, and operations.
    • Iterator: Provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
    • Template Method: Defines the skeleton of an algorithm in a base class, allowing subclasses to override specific steps of the algorithm.
    • State: Allows an object to alter its behavior when its internal state changes.
    • Chain of Responsibility: Enables an object to pass a request along a chain of potential handlers until one handles it.
    • Mediator: Defines an object that encapsulates how a set of objects interact, promoting loose coupling between them.
    • Visitor: Separates an algorithm from the objects it operates on by placing the algorithm in a separate visitor object.
    • Interpreter: Defines a representation of a grammar and provides a way to evaluate and interpret sentences in that grammar
    • Memento: Allows capturing and restoring the internal state of an object without violating encapsulation

Each pattern has a specific intent and addresses different aspects of software design. It's important to choose and apply patterns appropriately based on the problem at hand and the specific requirements of the software system.

Design patterns emerge in the course of daily work. The fact that GoF recognized the power of the pattern language in software design and published the first book on the subject by examining some of the most common OO decoupling challenges does not limit the patterns to the 23.

About

All design patterns in one place with C# code examples

Topics

Resources

Stars

Watchers

Forks