Skip to main content

Command Palette

Search for a command to run...

Low level Design (LLD)

Published
2 min readView as Markdown

A design pattern is a general, reusable solution to a common problem in software design. It’s not a piece of code you can copy and paste, but rather a template or guideline for how to solve a specific type of problem in a particular context.

Think of it like a blueprint that software developers can follow to solve recurring issues in software architecture or design.

Types of Design Patterns (categorized by purpose):

  1. Creational Patterns – Deal with object creation:

    • Singleton

    • Factory Method

    • Abstract Factory

    • Builder

    • Prototype

  2. Structural Patterns – Deal with object composition and relationships:

    • Adapter

    • Decorator

    • Composite

    • Proxy

    • Facade

    • Bridge

    • Flyweight

  3. Behavioral Patterns – Deal with object communication:

    • Observer

    • Strategy

    • Command

    • State

    • Chain of Responsibility

    • Template Method

    • Iterator

    • Mediator

    • Visitor


Strategy Design Pattern

  • The Strategy Design Pattern is a behavioral design pattern that enables selecting an algorithm or behavior at runtime. It defines a family of algorithms, encapsulates each one, and makes them interchangeable. This pattern lets the algorithm vary independently from clients that use it.

When to Use It:

  • You have multiple related classes that differ only in their behavior.

  • You want to make your code more flexible and reusable.

Concepts:

  • Context: The class that uses a Strategy.

  • Strategy Interface: Common interface for all supported algorithms.

  • Concrete Strategies: Classes that implement different algorithms using the Strategy interface.

Example: Document Export Framework

You have:

  • A base class: BaseExporter

  • Subclasses: InvoiceExporter, ReportExporter, SummaryExporter

  • Each one needs to export data differently, but some of them use the same logic (e.g., PDF or Excel export).

  • Instead of duplicating logic in each subclass, we delegate export behavior to strategy classes.