Skip to main content

Command Palette

Search for a command to run...

Introduction to LLD (Low Level Design)

Updated
4 min readView as Markdown
Introduction to LLD (Low Level Design)
S
Failure is life's greatest teacher

Introduction to Low-Level Design (LLD)

Relying on unstructured, "vibe-coded" production software is a recipe for disaster. Low-Level Design (LLD) zooms directly into the internal mechanics of your system, defining the exact class modules and how they communicate.

most devlopers spend time on debuging and analysis , meetings , documentation and testing that means how code is writen is improtant

"A good codebase should be self explained no need of documentation" and it make easier

  • Understandable: Code becomes self-explanatory, largely eliminating the need for exhaustive external documentation.

  • Extensible: The architecture smoothly adapts to new requirements and feature gathering.

  • Maintainable: Streamlines tedious tasks like debugging, performance optimization, and package updates.

Difference between High-Level Design Low-Level Design

Before diving deep into code internals, it is crucial to understand where LLD stands relative to system architecture:

Feature

High-Level Design (HLD)

Low-Level Design (LLD)

Focus

Broad system architecture, overall system topology, macro-level components, servers, and databases.

Code internals, granular class structures, schema designs, UML diagrams, and how code modules interact.

Scope

Deciding which services exist, load balancers, CDN setups, and inter-service communication.

Deciding which classes exist, method parameters, data encapsulation, design patterns, and algorithm implementation.

Perspective

Macro-level bird's-eye view of the entire infrastructure.

Micro-level developer view of the actual source code.

Procedural Code vs. The OOP

Historically, procedural programming relied on a cascade of functions calling other functions.

  • The Problem: It creates massive inter-dependencies, making complex software incredibly difficult to make sense of and tedious to debug.

  • The Missing "Free Will": In procedural code, entities are completely passive. A Student struct merely holds raw data, while external procedures perform actions on it.

// Procedural: Entities lack behavior
struct Student { int age; String name; }
void increaseAge(Student s, int offset) { s.age += offset; }

Object-Oriented Programming (OOP) bridges this gap by unifying data (attributes) and behavior (methods) into self-contained, active entities.

Abstraction - The Foundational Principle

Abstraction is the fundamental philosophy (the "Target" or "Vision") of OOP. It is the practice of representing a complex system purely as an idea.

  • What it does: It associates specific information and behaviors with an entity (like a Student, Assignment, or Batch) without requiring you to worry about internal complexities.

  • Real-World Example: When you turn a car's steering wheel, you do not need to understand the internal combustion engine or the rack-and-pinion mechanics. You just need to know what the action does, not how it works internally.

// Abstraction Example
public interface Car {
    void turn(String direction); // The "what" is exposed, the internal "how" is hidden
}

Pillars - Bringing Vision to Reality

If Abstraction is the conceptual vision, the three pillars Encapsulation, Inheritance, and Polymorphism are the tangible paths to making it a reality in code.

Encapsulation (The Capsule Analogy) Like a medical capsule, encapsulation packs the active ingredients (data and methods) together while protecting them from external contamination.

  • Groups the data and attributes of an idea into a single, cohesive unit.

  • Hides unnecessary internal workings from the outside world.

  • Exposes strictly what clients need to see, providing a cleaner, safer developer experience.

Classes, Objects, and Constructors

Concept Definition & Memory Footprint Real-World Context
Class A theoretical blueprint or structure. Occupies zero memory. The abstract idea of a Student.
Object A tangible runtime entity. Occupies actual memory space. "Shivam" (a physical instance storing real data).

Mastering Constructors Constructors act as specialized methods used to create and return an instance of a class.

  • Default Constructor: If omitted, the compiler provides a default that initializes attributes to their base values (e.g., int = 0, String = null).

  • Parameterized Constructor: Utilizes the this keyword to resolve naming ambiguity between class attributes and the parameters being passed in.

  • Copy Constructor: Creates a new object by copying the attribute values directly from another object of the same class, which ties directly into how shallow and deep copies are handled in memory.

public class Student {
    int age;
    String name;
    String gender = "male"; // Takes this default if not explicitly passed

    // Parameterized Constructor
    public Student(int age, String name) {
        this.age = age;   // 'this' removes variable ambiguity
        this.name = name;
    }

    // Copy Constructor
    public Student(Student other) {
        this.age = other.age;     
        this.name = other.name;   
    }
}