0
0
LLDsystem_design~25 mins

SOLID violations and fixes in LLD - System Design Exercise

Choose your learning style9 modes available
Design: SOLID Principles Violation and Fix Demonstration
In scope: Identifying and fixing violations of Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion principles. Out of scope: Full application implementation or complex business logic.
Functional Requirements
FR1: Show examples of common SOLID principle violations in a simple system
FR2: Explain how to fix each violation with proper design changes
FR3: Demonstrate the impact of fixes on code maintainability and scalability
Non-Functional Requirements
NFR1: Use simple, understandable examples suitable for beginners
NFR2: Focus on design and architecture, not language-specific syntax
NFR3: Keep examples small and focused on one principle violation at a time
Think Before You Design
Questions to Ask
❓ Question 1
❓ Question 2
❓ Question 3
❓ Question 4
❓ Question 5
Key Components
Classes or modules violating a principle
Interfaces or abstractions to separate concerns
Dependency injection mechanisms
Extension points for open/closed principle
Design Patterns
Single Responsibility Principle (SRP)
Open/Closed Principle (OCP)
Liskov Substitution Principle (LSP)
Interface Segregation Principle (ISP)
Dependency Inversion Principle (DIP)
Reference Architecture
  +----------------+       +-------------------+
  |  Client Code   | ----> |  Service Interface |
  +----------------+       +-------------------+
                                  ^
                                  |
                   +-------------------------------+
                   |       Concrete Service         |
                   +-------------------------------+

  Violations occur when:
  - Client depends on concrete classes directly
  - Classes have multiple responsibilities
  - Interfaces force methods not needed by clients
  - Subclasses break expected behavior

  Fixes:
  - Separate responsibilities into classes
  - Use interfaces for abstraction
  - Follow LSP by ensuring subclasses behave correctly
  - Split interfaces into smaller ones
  - Inject dependencies via abstractions
Components
Client Code
Any OO language
Uses services via interfaces, should not depend on concrete implementations
Service Interface
Interface or abstract class
Defines contract for services, enabling open/closed and dependency inversion
Concrete Service
Class implementing interface
Implements service logic, follows single responsibility
Request Flow
1. Client calls methods on Service Interface, not concrete classes
2. Concrete Service implements interface methods with focused responsibility
3. Dependencies are injected into Client or Service to avoid tight coupling
4. Interfaces are split so clients only depend on needed methods
5. Subclasses override behavior without breaking expected contracts
Database Schema
Not applicable - focus is on class design and interfaces
Scaling Discussion
Bottlenecks
Tight coupling makes changes risky and slow
Large classes with multiple responsibilities are hard to maintain
Clients forced to depend on unused methods cause unnecessary changes
Subclasses that break base class behavior cause bugs
Hard-coded dependencies reduce flexibility
Solutions
Apply Single Responsibility Principle to split classes
Use Open/Closed Principle to extend behavior without modifying existing code
Follow Interface Segregation Principle to create focused interfaces
Ensure Liskov Substitution Principle by designing correct inheritance
Use Dependency Inversion Principle to depend on abstractions and inject dependencies
Interview Tips
Time: Spend 10 minutes explaining each SOLID principle violation with example, then 5 minutes on fixes and benefits.
Explain what each SOLID principle means in simple terms
Show clear examples of violations and why they cause problems
Describe how fixes improve code quality and system flexibility
Mention how these principles help scale and maintain large systems
Use analogies like separating chores among people to explain SRP