SOLID Design Principles Tutorial
Lesson 30 of 98 31% of course

LSP Bad Example — Complete Guide

1 · 9 min · 5/24/2026

Learn LSP Bad Example — Complete Guide in our free SOLID Design Principles Tutorial series. Step-by-step explanations, examples, and interview tips on Toolliyo Academy.

Sign in to track progress and bookmarks.

LSP Bad Example — Complete Guide — ShopNest Clean Architecture
Article 32 of 100 · Module 4: Liskov Substitution Principle (LSP) · Audit Logs
Target keyword: lsp bad example solid principles c# · Read time: ~24 min · .NET: 8 / 9 · Project: ShopNest Clean Architecture — Audit Logs

Introduction

LSP Bad Example — Complete Guide is essential for .NET developers building ShopNest Enterprise Clean Architecture Platform — Toolliyo's 100-article SOLID Design Principles master path covering SRP, OCP, LSP, ISP, DIP, refactoring, Clean Architecture, and enterprise projects. Every article includes minimum 2 detailed enterprise real-world examples with bad code before good code (banking, e-commerce, ERP, SaaS, healthcare).

In Indian delivery projects (TCS, Infosys, Wipro), interviewers expect lsp bad example with real HDFC-style banking SRP fixes, Flipkart OCP payment strategies, TCS ERP LSP, Freshworks ISP, or Apollo hospital refactoring examples — not toy animal demos. This article delivers two mandatory enterprise examples on Audit Logs.

After this article you will

  • Explain LSP Bad Example in plain English and in SOLID principles and maintainable OOP terms
  • Implement lsp bad example in ShopNest Enterprise Clean Architecture Platform (Audit Logs)
  • Compare the wrong approach vs the production-ready enterprise approach
  • Answer fresher, mid-level, and senior SOLID principles and clean architecture interview questions confidently
  • Connect this lesson to Article 33 and the 100-article SOLID Principles roadmap

Prerequisites

Concept deep-dive

Level 1 — Analogy

LSP is like substituting any licensed driver — the car must behave predictably; a toy pedal car cannot replace a real car in a race.

Level 2 — Technical

LSP Bad Example integrates with the LINQ query layer: write queries against IEnumerable or IQueryable, understand deferred execution, project to DTOs for ShopNest Clean Architecture reports. On ShopNest Clean Architecture this powers Audit Logs without coupling UI to database internals.

Level 3 — Architecture

[Browser] → [HTTPS/Kestrel] → [Middleware Pipeline]
  → [Routing] → [Controller Action] → [Service Layer]
  → [EF Core / Identity] → [Razor View Engine] → [HTML Response]

Common misconceptions

❌ MYTH: LSP Bad Example is only for senior architects on huge systems.
✅ TRUTH: ShopNest applies SOLID from day one — even small modules benefit when the team will grow beyond one developer.

❌ MYTH: SOLID means creating an interface for everything.
✅ TRUTH: Apply abstractions when you have multiple implementations or need test doubles — not prematurely.

❌ MYTH: Refactoring to SOLID always slows delivery.
✅ TRUTH: Short-term cost pays back in faster testing, fewer merge conflicts, and safer changes within 2–3 sprints.

Project structure

ShopNest Clean Architecture/
├── ShopNest Clean Architecture/
├── src/
│   ├── ShopNest Clean Architecture.Api/       ← ASP.NET Core Web API
│   ├── ShopNest Clean Architecture.Core/      ← Repository interfaces
│   ├── ShopNest Clean Architecture.AdoNet/    ← SqlConnection, SPs, transactions
│   ├── ShopNest Clean Architecture.Reports/   ← Streaming readers, GL reports
│   └── ShopNest Clean Architecture.Tests/     ← Integration tests (Testcontainers SQL)
├── sql/
│   ├── migrations/
│   └── stored-procedures/
└── docker-compose.yml                 ← SQL Server 2022 + Redis

Step-by-Step Implementation — ShopNest (Audit Logs)

Follow the prompt template: create project → core classes → interfaces → pattern implementation → client code → run → enterprise refactor.

Step 1 — The wrong way

// ❌ BAD — god class violates SRP, tight coupling, untestable
public class OrderService {
    public void PlaceOrder(Order o) {
        Validate(o);
        _context.Orders.Add(o);
        _context.SaveChanges();
        SendEmail(o.CustomerEmail);
        GenerateInvoicePdf(o);
    }
}

Step 2 — The right way

// ✅ CORRECT — LSP Bad Example on ShopNest (Audit Logs) — SOLID applied
public sealed class PlaceOrderHandler(IOrderRepository repo, INotificationService notify)
    : IRequestHandler
{
    public async Task Handle(PlaceOrderCommand cmd, CancellationToken ct) {
        var order = Order.Create(cmd.CustomerId, cmd.Items);
        await repo.AddAsync(order, ct);
        await notify.OrderPlacedAsync(order, ct);
        return Result.Success(order.Id);
    }
}

Step 3 — Apply LSP Bad Example

// LSP Bad Example — ShopNest Clean Architecture (Audit Logs)
builder.Services.AddScoped<ILSPBadExampleService, LSPBadExampleService>();
dotnet run --project ShopNest Clean Architecture.Api
# Verify LSP Bad Example — check Swagger UI and unit test pass rate and integration tests pass

The problem before SOLID

Without SOLID, ShopNest teams hit: tight coupling, god classes, untestable controllers, merge conflicts, and fear of refactoring. Indian IT projects (TCS, Infosys, Wipro) lose sprints when legacy code has no clear boundaries.

  • Tight coupling — change SMS provider, break ledger posting
  • Testing difficulty — cannot mock database from controller
  • Scalability — monolith teams block each other
  • Bug-prone — one class, five reasons to change

Real-time refactoring walkthrough — LSP

Step 1: Identify violation → Step 2: Extract interface → Step 3: Split responsibilities → Step 4: Register in DI → Step 5: Add unit tests. Commit each step separately for safe code review.

Real-World Example 1 — TCS ERP — LSP with Employee Hierarchy

MANDATORY enterprise scenario (Enterprise ERP): LSP Bad Example applied in ShopNest Clean Architecture Audit Logs.

Business problem

ContractEmployee inherited FullTimeEmployee but threw NotImplementedException on ApplyBonus(). LSP violation broke payroll batch. Fixed with IEmployee interface and separate bonus policies.

Before SOLID — bad design

public class ContractEmployee : FullTimeEmployee {
    public override void ApplyBonus(decimal amount) =>
        throw new NotImplementedException("Contractors get no bonus");
}

After SOLID — production design

public interface IEmployee {
    decimal CalculatePay(PayPeriod period);
}
public class FullTimeEmployee : IEmployee { /* bonus eligible */ }
public class ContractEmployee : IEmployee { /* no bonus — no fake override */ }

Outcome

Payroll batch stopped throwing at 2 AM; HR can add new employment types without breaking existing workers.

Real-World Example 2 — Freshworks CRM — ISP on Fat ICustomerService

MANDATORY enterprise scenario (SaaS CRM): LSP Bad Example applied in ShopNest Clean Architecture Audit Logs.

Business problem

ICustomerService had 18 methods; read-only report API was forced to implement DeleteCustomer and MergeDuplicates. ISP split into ICustomerReader, ICustomerWriter, ICustomerAdmin.

Before SOLID — bad design

public interface ICustomerService {
    Customer Get(int id); void Create(Customer c); void Delete(int id);
    void Merge(int a, int b); byte[] ExportPdf(); /* 13 more... */
}

After SOLID — production design

public interface ICustomerReader { Customer Get(int id); IReadOnlyList<Customer> Search(string q); }
public interface ICustomerWriter { void Create(Customer c); void Update(Customer c); }
public interface ICustomerAdmin { void Delete(int id); void Merge(int a, int b); }

Outcome

Report microservice depends only on ICustomerReader — security audit passed least-privilege review.

SOLID in ASP.NET Core — LSP Bad Example

Register abstractions in Program.cs as Scoped. Keep controllers thin — delegate to MediatR handlers or application services. ShopNest Clean Architecture: Domain → Application → Infrastructure → Api.

builder.Services.AddScoped<IOrderService, OrderService>();
builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(PlaceOrderHandler).Assembly));

SOLID and design patterns

SRP enables focused classes; OCP pairs with Strategy and Factory; LSP guards inheritance; ISP splits fat interfaces; DIP powers DI and Repository pattern. SOLID is the foundation — patterns are the tools.

Unit testing with SOLID

var mock = new Mock<IOrderRepository>();
mock.Setup(r => r.GetAsync(1, default)).ReturnsAsync(new Order(1, 100m));
var handler = new GetOrderHandler(mock.Object);
var result = await handler.Handle(new GetOrderQuery(1), default);
Assert.Equal(100m, result.Total);

Common errors & fixes

🔴 Mistake 1: God classes with 10+ responsibilities (SRP violation)
Fix: Extract focused services — one reason to change per class.

🔴 Mistake 2: Adding if/else chains for every new feature (OCP violation)
Fix: Use Strategy or Factory; extend via new classes, not edits.

🔴 Mistake 3: Subclass throws NotImplementedException (LSP violation)
Fix: Prefer composition and role-specific interfaces over broken inheritance.

🔴 Mistake 4: Controllers new-ing concrete repositories (DIP violation)
Fix: Inject interfaces via constructor DI in ASP.NET Core.

Best practices

  • 🟢 Use async/await end-to-end for database and I/O calls
  • 🟢 Register DbContext as Scoped; avoid capturing it in singletons
  • 🟡 Use IQueryable until the last moment; avoid multiple enumeration; project with Select before ToList
  • 🟡 Prefer method syntax for complex chains; use query syntax for joins when readability wins
  • 🔴 Log structured data with Serilog — include OrderId, UserId, not passwords
  • 🔴 Use HTTPS, secure cookies, and authorization policies in production

Interview questions

Fresher level

Q1: What is LSP Bad Example in ASP.NET Core MVC?
A: LSP Bad Example is a core MVC capability used in ShopNest Clean Architecture for Audit Logs. Explain in one sentence, then describe controller/view/service placement.

Q2: How would you implement LSP Bad Example on a TCS-style delivery project?
A: Deferred execution, IQueryable pipelines, Select projection, Skip/Take pagination, and SQL logging in development.

Q3: IEnumerable vs IQueryable — when to use which?
A: IEnumerable for in-memory collections; IQueryable for EF Core database queries that translate to SQL.

Mid / senior level

Q4: Explain LINQ deferred execution and query translation briefly.
A: LINQ → Expression Tree → IQueryProvider → SQL (EF) or Iterator (in-memory) → Results.

Q5: Common production mistake with this topic?
A: Skipping validation, exposing secrets in Git, or untested edge cases (null model, unauthorized user).

Q6: .NET LINQ vs SQL — when to push logic to database?
A: Core is cross-platform, faster, cloud-ready; Framework is maintenance mode on Windows/IIS.

Coding round

Implement LSP Bad Example for ShopNest Audit Logs: show interface, concrete class, DI registration, and xUnit test with mock.

public class LSPBadExamplePatternTests
{
    [Fact]
    public async Task ExecuteAsync_ReturnsSuccess()
    {
        var mock = new Mock();
        mock.Setup(s => s.ExecuteAsync(It.IsAny(), default))
            .ReturnsAsync(Result.Success("test-id"));
        var result = await mock.Object.ExecuteAsync(new Request("test-id"));
        Assert.True(result.IsSuccess);
    }
}

Summary & next steps

  • Article 32: LSP Bad Example — Complete Guide
  • Module: Module 4: Liskov Substitution Principle (LSP) · Level: INTERMEDIATE
  • Applied to ShopNest Clean Architecture — Audit Logs

Previous: Liskov Substitution Principle — Complete Guide
Next: LSP Refactoring — Complete Guide

Practice: Add one small feature using today's pattern — commit with feat(solid): article-32.

FAQ

Q1: What is LSP Bad Example?

LSP Bad Example helps ShopNest Clean Architecture implement Audit Logs using C# 12 LINQ with EF Core where applicable.

Q2: Do I need Visual Studio?

No — .NET 8 SDK with VS Code + C# Dev Kit works. Visual Studio 2022 Community is recommended for MVC scaffolding.

Q3: Is this asked in Indian IT interviews?

Yes — MVC topics from Modules 1–6 appear in TCS, Infosys, Wipro campus drives; architecture modules in lateral hires.

Q4: Which .NET version?

Examples target .NET 8 LTS and .NET 9 with C# 12+ syntax.

Q5: How does this fit ShopNest Clean Architecture?

Article 32 adds lsp bad example to Audit Logs. By Article 100 you have a portfolio-ready ShopNest Clean Architecture enterprise database layer.

Test your knowledge

Quizzes linked to this course—pass to earn certificates.

Browse all quizzes
SOLID Design Principles Tutorial

On this page

Introduction After this article you will Prerequisites Concept deep-dive Level 1 — Analogy Level 2 — Technical Level 3 — Architecture Project structure Step-by-Step Implementation — ShopNest (Audit Logs) Step 1 — The wrong way Step 2 — The right way Step 3 — Apply LSP Bad Example The problem before SOLID Real-time refactoring walkthrough — LSP Real-World Example 1 — TCS ERP — LSP with Employee Hierarchy Business problem Before SOLID — bad design After SOLID — production design Outcome Real-World Example 2 — Freshworks CRM — ISP on Fat ICustomerService Business problem Before SOLID — bad design After SOLID — production design Outcome SOLID in ASP.NET Core — LSP Bad Example SOLID and design patterns Unit testing with SOLID Common errors &amp; fixes Best practices Interview questions Fresher level Mid / senior level Coding round Summary &amp; next steps FAQ Q1: What is LSP Bad Example? Q2: Do I need Visual Studio? Q3: Is this asked in Indian IT interviews? Q4: Which .NET version? Q5: How does this fit ShopNest Clean Architecture?
Module 1: SOLID Foundations
Introduction to SOLID Principles — Complete Guide Why SOLID Principles Matter — Complete Guide SOLID vs Bad Architecture — Complete Guide SOLID in Enterprise Applications — Complete Guide SOLID in ASP.NET Core — Complete Guide SOLID and Design Patterns — Complete Guide SOLID and Dependency Injection — Complete Guide SOLID Interview Questions Overview — Complete Guide
Module 2: Single Responsibility Principle (SRP)
Single Responsibility Principle — Complete Guide SRP Bad Example — Complete Guide SRP Refactoring — Complete Guide SRP in ASP.NET Core — Complete Guide SRP Real-Time Banking Example — Complete Guide SRP Real-Time E-Commerce Example — Complete Guide SRP Testing Benefits — Complete Guide SRP Performance Considerations — Complete Guide SRP Common Mistakes — Complete Guide SRP Interview Questions — Complete Guide
Module 3: Open/Closed Principle (OCP)
Open Closed Principle — Complete Guide OCP Bad Example — Complete Guide OCP Refactoring — Complete Guide OCP Using Strategy Pattern — Complete Guide OCP in Payment Gateway — Complete Guide OCP in Notification Systems — Complete Guide OCP in ASP.NET Core — Complete Guide OCP Performance Considerations — Complete Guide OCP Common Mistakes — Complete Guide OCP Interview Questions — Complete Guide
Module 4: Liskov Substitution Principle (LSP)
Liskov Substitution Principle — Complete Guide LSP Bad Example — Complete Guide LSP Refactoring — Complete Guide LSP in Enterprise Systems — Complete Guide LSP Banking Example — Complete Guide LSP ERP Example — Complete Guide LSP in ASP.NET Core — Complete Guide LSP Common Mistakes — Complete Guide LSP Testing Benefits — Complete Guide LSP Interview Questions — Complete Guide
Module 5: Interface Segregation Principle (ISP)
Interface Segregation Principle — Complete Guide ISP Bad Example — Complete Guide ISP Refactoring — Complete Guide ISP in Clean Architecture — Complete Guide ISP Real-Time CRM Example — Complete Guide ISP Real-Time Inventory Example — Complete Guide ISP in ASP.NET Core — Complete Guide ISP Common Mistakes — Complete Guide ISP Performance Considerations — Complete Guide ISP Interview Questions — Complete Guide
Module 6: Dependency Inversion Principle (DIP)
Dependency Inversion Principle — Complete Guide DIP Bad Example — Complete Guide DIP Refactoring — Complete Guide DIP with Dependency Injection — Complete Guide DIP in ASP.NET Core — Complete Guide DIP in Microservices — Complete Guide DIP Banking Example — Complete Guide DIP Notification System Example — Complete Guide DIP Common Mistakes — Complete Guide DIP Interview Questions — Complete Guide
Module 7: SOLID in Real-World Architecture
SOLID in Clean Architecture — Complete Guide SOLID in DDD — Complete Guide SOLID in CQRS — Complete Guide SOLID in Vertical Slice Architecture — Complete Guide SOLID in Microservices — Complete Guide SOLID in Event-Driven Systems — Complete Guide SOLID in API Design — Complete Guide SOLID in Distributed Systems — Complete Guide SOLID in Cloud-Native Architecture — Complete Guide SOLID in Enterprise SaaS Platforms — Complete Guide
Module 8: Refactoring and Clean Code
Refactoring Legacy Code — Complete Guide Breaking Monolith Code — Complete Guide Reducing Tight Coupling — Complete Guide Removing God Classes — Complete Guide Interface Refactoring — Complete Guide Service Layer Refactoring — Complete Guide Controller Refactoring — Complete Guide Repository Refactoring — Complete Guide Dependency Injection Refactoring — Complete Guide Enterprise Refactoring Strategies — Complete Guide
Module 9: Testing and Maintainability
Unit Testing with SOLID — Complete Guide Mocking with Interfaces — Complete Guide xUnit and Moq — Complete Guide Integration Testing — Complete Guide Testable Architecture — Complete Guide Scalable Architecture — Complete Guide Team Collaboration Benefits — Complete Guide Maintainable Codebases — Complete Guide Performance Considerations — Complete Guide Enterprise Development Standards — Complete Guide
Module 10: Real-World Enterprise Projects
Banking System Architecture — Complete Guide E-Commerce Platform — Complete Guide ERP System — Complete Guide CRM Platform — Complete Guide Hospital Management System — Complete Guide Inventory Management System — Complete Guide SaaS Multi-Tenant Platform — Complete Guide Payment Gateway System — Complete Guide Notification Platform — Complete Guide Enterprise Cloud-Native Platform — Capstone