21 Feb 2024

Design patterns

Introduction

A design pattern is a reusable and generalized solution to common problems in software design. It serves as a blueprint, providing a conceptual framework rather than specific code, allowing developers to tailor the solution to the specific needs of their programs. Unlike algorithms, which prescribe a specific set of actions to achieve a goal, design patterns offer a higher-level description of a solution. The pattern typically includes sections such as intent, motivation, structure of classes, and a code example in a popular programming language. These formal descriptions enable developers to understand, apply, and adapt the pattern to various contexts, promoting consistency and best practices in software development.

Classification of patterns

Design patterns exhibit varying levels of complexity, detail, and applicability across a system's scope, analogous to the diverse approaches in road construction, ranging from simple traffic lights to intricate multi-level interchanges. At the most fundamental level are idioms, addressing language-specific nuances, while architectural patterns offer a universal, high-level framework adaptable to diverse languages for designing entire applications. This classification extends to patterns' intent, with three primary groups covered in this context. Creational patterns focus on object creation mechanisms to enhance flexibility and code reuse. Structural patterns guide the assembly of objects into efficient, flexible structures, while behavioral patterns facilitate effective communication and delineate responsibilities among objects. This systematic categorization aids developers in selecting and applying patterns tailored to specific design challenges and requirements they encounter.

three main groups of patterns:

  • Creational patterns provide object creation mechanisms that increase flexibility and reuse of existing code

  • Structural patterns explain how to assemble objects and classes into larger structures, while keeping these structures flexible and efficient.

  • Behavioral patterns take care of effective communication and the assignment of responsibilities between objects.

Creational patterns

A creational pattern is a type of design pattern that deals with the process of object creation in software development. It provides mechanisms for creating objects in a manner that is flexible, efficient, and promotes the reuse of existing code. Creational patterns are particularly useful when the exact classes or objects to be created are not known until runtime or when the creation process must be abstracted from the client code.

Common creational patters:

Structural patterns

Structural patterns are a category of design patterns that focus on simplifying the organization and composition of classes and objects. These patterns help define clear relationships and interfaces between different components, ensuring that the system's structure is flexible, efficient, and easy to understand. Structural patterns are particularly useful when dealing with the composition of classes and objects to form larger structures or when adapting interfaces between incompatible systems.

Common structural patterns:

  • Adapter pattern

  • Bridge patten

  • Composite pattern

  • Decorator pattern

  • Facade pattern

  • Proxy pattern

Behavioral patterns

Behavioral patterns are a category of design patterns that focus on the interaction, communication, and assignment of responsibilities between objects in a software system. These patterns help define how objects collaborate and operate to achieve a common goal, emphasizing the flow of communication and the delegation of tasks. Behavioral patterns are particularly useful for addressing the dynamic aspects of a system, such as the runtime behavior and interactions between different objects.

Common behavioral pattern:

  • Chain of responsibility pattern

  • Command pattern

  • Iterator pattern

  • Mediator Pattern

  • Memento pattern

  • State pattern

  • Strategy pattern

  • Template pattern

  • Visitor pattern

← Back to Library