Skip to content

Latest commit

 

History

History
141 lines (96 loc) · 6.83 KB

README.md

File metadata and controls

141 lines (96 loc) · 6.83 KB

Design Patterns

A design pattern is just a guide to show you how to solve a repeatable problem. Depending of the design problem, you can classify the design patterns in three main categories; creational, structural and behavioral patterns. This is called Gamma Categorization after Erich Gamma, one of the "Gang of Four" book authors.

Table Of Content

  1. Introduction
    1. Solid Principles
  2. Creational Patterns
    1. Builder
      1. Builder ✔️
      2. Fluent Builder ✔️
      3. Groovy-style Builder ✔️
    2. Singleton ✔️
    3. Multiton ✔️
    4. Factory
      1. Factory Method ✔️
      2. Inner Factory ✔️
      3. Abstract Factory ✔️
      4. Functional Factory ✔️
    5. Prototype
      1. Prototype ✔️
      2. Prototype Factory ✔️
    6. Object Pool
  3. Structural Patterns
    1. Adapter ✔️
    2. Bridge
      1. Bridge ✔️
      2. Pimpl Idiom ✔️
    3. Composite
      1. Geometric Shapes Example ✔️
    4. Decorator
    5. Facade
    6. Flyweight
    7. Proxy
    8. Private Class Data
  4. Behavioral Patterns
    1. Chain Of Responsibility
    2. Command
    3. Interpreter
    4. Iterator
    5. Mediato
    6. Memento
    7. Observer
    8. State ✔️
    9. Strategy
    10. Template Method
    11. Visitor
    12. Model-View-Controller
    13. Null Object

Solid Design Principles

  • Single Responsibility Principle

    • A class should only have one reason to change.
    • Separation of concerns - different classes handling different, independent task/problems.
  • Open-Closed Principle

    • Classe should be open for extension but closed for modification.
  • Liskov Substitution Principle

    • You should be able to substitute a base type for a subtype.
  • Interface Segregation Principle

    • Don't put too much into an interface; split into separete interfaces.
    • YAGNI - You Ain't Going to Need It
  • Dependency Inversion Principle

    • High-level modules should not depend upon low-level ones; use abstractions.

Creational Patterns

These design patterns are all about class instantiation. This pattern can be further divided into class-creation patterns and object-creational patterns. While class-creation patterns use inheritance effectively in the instantiation process, object-creation patterns use delegation effectively to get the job done.

Builder

  • Builder

  • Fluent Builder

  • Groovy-style Builder

Singleton

The singleton pattern is a software design pattern that restricts the instantiation of a class to one "single" instance. This is useful when exactly one object is needed to coordinate actions across the system. The term comes from the mathematical concept of a singleton.

Critics consider the singleton to be an anti-pattern in that it is frequently used in scenarios where it is not beneficial, introduces unnecessary restrictions in situations where a sole instance of a class is not actually required, and introduces global state into an application.

Multiton

The multiton pattern is a design pattern which generalizes the singleton pattern. Whereas the singleton allows only one instance of a class to be created, the multiton pattern allows for the controlled creation of multiple instances, which it manages through the use of a map.

Factory

  • Factory Method

  • Inner Factory

  • Abstract Factory

  • Functional Factory

Prototype

  • Prototype

  • Prototype Factory

Structural Patterns

In software engineering, structural design patterns are design patterns that ease the design by identifying a simple way to realize relationships among entities.

Adapter

The adapter pattern is a software design pattern (also known as wrapper, an alternative naming shared with the decorator pattern) that allows the interface of an existing class to be used as another interface. It is often used to make existing classes work with others without modifying their source code.

Bridge

The bridge pattern is a design pattern used in software engineering that is meant to "decouple an abstraction from its implementation so that the two can vary independently". The bridge uses encapsulation, aggregation, and can use inheritance to separate responsibilities into different classes.

  • Bridge

  • Pimpl Idiom

Composite

The composite pattern is a partitioning design pattern. The composite pattern describes a group of objects that are treated the same way as a single instance of the same type of object. The intent of a composite is to "compose" objects into tree structures to represent part-whole hierarchies.

  • Geometric Shapes Example

    This example create multiple shapes objects, circle, square and rectangle, and group than into a tree view using groups of objects.

Behavioral Patterns

In software engineering, behavioral design patterns are design patterns that identify common communication patterns among objects and realize these patterns. By doing so, these patterns increase flexibility in carrying out this communication.

State

The state pattern is a behavioral software design pattern that allows an object to alter its behavior when its internal state changes. This pattern is close to the concept of finite-state machines. The state pattern can be interpreted as a strategy pattern, which is able to switch a strategy through invocations of methods defined in the pattern's interface.