0
0
LLDsystem_design~12 mins

Liskov Substitution Principle in LLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - Liskov Substitution Principle

The Liskov Substitution Principle (LSP) is a key idea in software design. It says that objects of a parent class should be replaceable with objects of a child class without breaking the program. This helps keep code easy to understand, maintain, and extend.

In system design, following LSP means designing components so that new versions or types can replace old ones smoothly, ensuring system stability and scalability.

Architecture Diagram
          +-------------------+
          |   Client System    |
          +---------+---------+
                    |
                    v
          +-------------------+
          |   Base Component   |
          |  (Parent Class)    |
          +---------+---------+
                    |
        +-----------+-----------+
        |                       |
+---------------+       +---------------+
| Derived A     |       | Derived B     |
| (Child Class) |       | (Child Class) |
+---------------+       +---------------+
                    |
                    v
          +-------------------+
          |  Shared Interface  |
          +-------------------+
Components
Client System
client
Uses components through a shared interface without knowing their exact types.
Base Component
service
Defines common behavior and interface for all derived components.
Derived A
service
Implements specific behavior while fully respecting the base component's contract.
Derived B
service
Another implementation that can replace the base component without breaking the client.
Shared Interface
interface
Defines the contract that all components must follow to ensure substitutability.
Request Flow - 4 Hops
Client SystemBase Component
Base ComponentDerived A or Derived B
Derived A or Derived BShared Interface
Derived A or Derived BClient System
Failure Scenario
Component Fails:Derived B
Impact:If Derived B violates LSP by changing expected behavior, client system may get incorrect results or errors.
Mitigation:Use thorough testing and interface contracts to ensure Derived B respects base component behavior before deployment.
Architecture Quiz - 3 Questions
Test your understanding
What does the Liskov Substitution Principle ensure in system design?
AChild components can replace parent components without breaking the system
BParent components must never be extended
CChild components can have completely different interfaces
DClients must know the exact type of components they use
Design Principle
The Liskov Substitution Principle promotes designing components that can be replaced by their subtypes without changing the correctness of the system. This principle helps build flexible and maintainable systems by enforcing consistent behavior through shared interfaces.