4 PILLARS OF LLD ???
4 PILLARS OF LLD ???
**********************************
1)Strong in OOPS Concepts.
2) Design Principles (SOLID, DRY, KISS, YAGNI, Law of Demeter, Composition Over Inheritance)
3) Design Patterns.
4)Β UML Diagrams.
********************************

1)Strong in OOPS Concepts
4 PILLARS OF LLD ???
OOP Concept | Description | Example in C++ |
---|---|---|
Class | A blueprint for creating objects that encapsulate data and methods. | class Car { int speed; void drive(); }; |
Object | An instance of a class with its values and behaviors. | Car myCar; myCar.drive(); |
Encapsulation | Wrapping data and methods into a single unit and restricting direct access. | private: int speed; public: void setSpeed(int s) { speed = s; } |
Abstraction | Hiding implementation details and exposing only necessary parts. | class Vehicle { virtual void start() = 0; }; |
Inheritance | Enabling a new class to derive properties and behaviors from an existing class. | class SportsCar : public Car { void turboBoost(); }; |
Polymorphism | The ability to take multiple forms, such as function overloading and overriding. | class Shape { virtual void draw(); }; class Circle : public Shape { void draw() override; }; |
Dynamic Binding | Deciding at runtime which functions to execute using virtual functions. | virtual void display(); |
Message Passing | Objects communicate with each other via function calls. | obj1.sendMessage(obj2); |
Constructor | A special function that initializes an object when it’s created. | Car() { speed = 0; } |
Destructor | A special function is called when an object is destroyed. | ~Car() { cout << "Car destroyed"; } |
2) Design Principles
4 PILLARS OF LLD ???
Design Principle | Description | Example in C++ |
---|---|---|
1. Single Responsibility Principle (SRP) | A class should have only one reason to change (one responsibility). | class Logger { void log(string msg); }; (Separating logging from business logic) |
2. Open/Closed Principle (OCP) | A class should be open for extension but closed for modification. | class Shape { virtual double area() = 0; }; (New shapes can be added without modifying existing code) |
3. Liskov Substitution Principle (LSP) | Derived classes should be replaceable for base classes without altering correctness. | class Bird { virtual void fly(); }; class Sparrow : public Bird {}; |
4. Interface Segregation Principle (ISP) | Clients should not be forced to depend on interfaces they do not use. | class Printer { virtual void print() = 0; }; class Scanner { virtual void scan() = 0; }; (Separate interfaces for different functionalities) |
5. Dependency Inversion Principle (DIP) | High-level modules should not depend on low-level modules. Both should depend on abstractions. | class Database { virtual void connect() = 0; }; class MySQL : public Database { void connect() override; }; |
6. DRY (Don’t Repeat Yourself) | Avoid duplication by reusing code. | Using functions, templates, and inheritance to eliminate redundant code. |
7. KISS (Keep It Simple, Stupid) | Write simple, clear, and maintainable code. | Avoid overly complex inheritance or nested logic. |
8. YAGNI (You Ainβt Gonna Need It) | Don’t add features until they are necessary. | Avoiding premature optimizations and unnecessary abstractions. |
9. Law of Demeter (LoD) | A class should have limited knowledge of other objects. | Using getters/setters instead of direct member access. |
10. Composition Over Inheritance | Prefer composition (has-a) over inheritance (is-a). | class Engine {}; class Car { Engine engine; }; (Instead of class Car : public Engine {} ) |
3) Design Patterns
4 PILLARS OF LLD ???
Category | Design Pattern | Description | Example in C++ |
---|---|---|---|
Creational | Singleton | Ensures that a class has only one instance and provides a global access point. | class Singleton { static Singleton* instance; public: static Singleton* getInstance(); }; |
Factory Method | Provides an interface for creating objects but lets subclasses alter the type of objects that will be created. | class Shape { public: virtual void draw() = 0; }; class ShapeFactory { Shape* createShape(string type); }; |
|
Abstract Factory | Creates families of related objects without specifying their concrete classes. | class GUIFactory { virtual Button* createButton() = 0; }; |
|
Builder | Separates the construction of a complex object from its representation. | class CarBuilder { void setEngine(); void setWheels(); }; class CarDirector { CarBuilder* builder; }; |
|
Prototype | Creates new objects by copying an existing object. | class Prototype { virtual Prototype* clone() = 0; }; |
|
Structural | Adapter | Converts the interface of a class into another interface clients expect. | class USB { void connect(); }; class USBAdapter { USB usb; void connectToLaptop(); }; |
Bridge | Separates an abstraction from its implementation so that both can be modified independently. | class Device { virtual void turnOn() = 0; }; class Remote { Device* device; }; |
|
Composite | Composes objects into tree structures to represent part-whole hierarchies. | class Component { virtual void operation() = 0; }; class Composite : public Component {}; |
|
Decorator | Attaches additional responsibilities to an object dynamically. | class Coffee { virtual string description() = 0; }; class MilkDecorator : public Coffee {}; |
|
Facade | Provides a simplified interface to a complex system. | class Facade { Subsystem1 s1; Subsystem2 s2; void operation(); }; |
|
Flyweight | Reduces memory usage by sharing common objects instead of creating new ones. | class Character { char symbol; }; class CharacterFactory { Character* getCharacter(char c); }; |
|
Proxy | Provides a surrogate or placeholder for another object. | class Image { virtual void display() = 0; }; class ProxyImage : public Image {}; |
|
Behavioral | Chain of Responsibility | Passes requests along a chain of handlers. | class Handler { Handler* next; void handleRequest(); }; |
Command | Encapsulates a request as an object. | class Command { virtual void execute() = 0; }; class ConcreteCommand : public Command {}; |
|
Interpreter | Defines a grammatical representation for a language and an interpreter to interpret sentences in the language. | class Expression { virtual int interpret() = 0; }; |
|
Iterator | Provides a way to access elements of an aggregate object sequentially without exposing its underlying representation. | class Iterator { virtual bool hasNext() = 0; virtual Object* next() = 0; }; |
|
Mediator | Defines an object that encapsulates how a set of objects interact. | class Mediator { virtual void notify(); }; class Component { Mediator* mediator; }; |
|
Memento | Captures and restores an objectβs internal state. | class Memento { private: string state; }; class Originator { Memento save(); void restore(Memento m); }; |
|
Observer | Defines a dependency between objects so that when one changes state, all its dependents are notified. | class Observer { virtual void update() = 0; }; class Subject { vector<Observer*> observers; void notify(); }; |
|
State | Allows an object to change its behavior when its internal state changes. | class State { virtual void handle() = 0; }; class Context { State* state; }; |
|
Strategy | Defines a family of algorithms, encapsulates each one, and makes them interchangeable. | class Strategy { virtual void execute() = 0; }; class ConcreteStrategy : public Strategy {}; |
|
Template Method | Defines the skeleton of an algorithm but allows subclasses to redefine certain steps. | class Template { void algorithm(); }; |
|
Visitor | Allows adding new operations to objects without modifying their structure. | class Visitor { virtual void visit(Element* e) = 0; }; class Element { virtual void accept(Visitor* v) = 0; }; |
4)Β UML Diagrams
UML Diagram Type | Description | Usage Example |
---|---|---|
Structural Diagrams | Depict static aspects of the system (classes, objects, relationships). | – |
Class Diagram | Represents classes, attributes, methods, and relationships between them. | Designing object-oriented systems (e.g., defining class relationships in C++). |
Object Diagram | Shows instances of classes and their relationships at a specific point in time. | Debugging object interactions during runtime. |
Component Diagram | Describes the physical structure of software components and their dependencies. | Microservices architecture, modular design in large applications. |
Deployment Diagram | Represents the physical deployment of artifacts (software) on hardware. | Cloud infrastructure, system architecture planning. |
Package Diagram | Groups related classes or components into packages. | Organizing large codebases into modules. |
Composite Structure Diagram | Shows the internal structure of a class and collaborations between its components. | Modeling complex components with sub-elements. |
Behavioral Diagrams | Depict dynamic aspects of the system (interactions, workflows, state changes). | – |
Use Case Diagram | Represents user interactions with the system. | Understanding system functionality from a user’s perspective. |
Sequence Diagram | Depicts the flow of messages between objects over time. | Designing API interactions, and process flow in a feature. |
Activity Diagram | Illustrates workflows, processes, and decision-making logic. | Modeling business processes, and login workflows. |
State Machine Diagram | Represents states of an object and transitions between them. | Designing state-based behavior, like vending machines. |
Communication Diagram | Similar to sequence diagrams, it focuses on object interactions. | Analyzing real-time communication between components. |
Timing Diagram | Shows changes in state or behavior over time. | Embedded systems, real-time system modeling. |
Interaction Overview Diagram | Combines activity and sequence diagrams for a high-level view of system interactions. | Representing complex workflows at a high level. |
Important UML Diagrams for Low-Level Design (LLD) Interviews
UML (Unified Modeling Language) diagrams help visualize, specify, construct, and document software systems. For LLD, these are the most important UML diagrams:
1. Class Diagram (Most Important)
π Purpose: Represents the static structure of a system, showing classes, attributes, methods, and relationships.
π Key Components:
- Classes (with attributes & methods)
- Relationships (Association, Aggregation, Composition, Inheritance)
- Access Modifiers (+ public, – private, # protected)
β Why Important? Used in LLD to define the object-oriented structure of a system.
2. Sequence Diagram
π Purpose: Shows the interaction between objects over time (i.e., the order of method calls).
π Key Components:
- Actors & Objects (Who initiates the interaction)
- Lifelines (Object existence)
- Messages/Method Calls (Solid arrow for synchronous, dashed for asynchronous)
β Why Important? Defines the flow of control and communication between objects for a use case.
3. Use Case Diagram
π Purpose: Represents how external users interact with the system.
π Key Components:
- Actors (Users or external systems)
- Use Cases (Functionalities)
- Relationships (Extend, Include, Generalization)
β Why Important? Helps in understanding functional requirements and user interactions.
4. Activity Diagram
π Purpose: Represents workflow and business logic.
π Key Components:
- Start & End nodes
- Actions (Processes)
- Decision points (if/else conditions)
- Swimlanes (For role-based responsibilities)
β Why Important? Helps in defining process flows and decision logic.
5. Component Diagram
π Purpose: Represents high-level system architecture, showing dependencies between components.
π Key Components:
- Components (Modules, Services)
- Interfaces (APIs)
- Dependency Relationships
β Why Important? Helps in understanding module interactions and dependencies.
6. Deployment Diagram
π Purpose: Represents physical deployment of software components on hardware nodes.
π Key Components:
- Nodes (Servers, Databases, Cloud, etc.)
- Artifacts (Deployed software components)
- Connections (Communication links between nodes)
β Why Important? Used in system architecture discussions for scalability and deployment planning.
Which UML Diagrams to Use in LLD?
UML Diagram | Used for |
---|---|
Class Diagram | Defining system structure (MUST HAVE) |
Sequence Diagram | Explaining object interactions (MUST HAVE) |
Use Case Diagram | Understanding user-system interaction |
Activity Diagram | Modeling workflows and logic |
Component Diagram | Showing module-level architecture |
Deployment Diagram | Understanding infrastructure and deployment |
How to Use UML in an LLD Interview?
1οΈβ£ Start with a Use Case Diagram β Identify functionalities.
2οΈβ£ Create a Class Diagram β Define classes, attributes, and relationships.
3οΈβ£ Draw a Sequence Diagram β Show object interactions for key flows.
4οΈβ£ Use an Activity Diagram β If business logic is complex.
5οΈβ£ Component & Deployment Diagrams β For large-scale system designs.
Follow us on :
4 PILLARS OF LLD ???
www.youtube.com/@TrendyVSVlogs
www.youtube.com/@VSCodingAcademy