Loading LLD::COSMOS...
Inspect legacy anti-pattern code smells and compare them with clean, decoupled SOLID refactorings side-by-side.
“A class should have one, and only one, reason to change.”
class OrderManager {
processOrder(order: Order) {
// 1. Business Logic
const total = order.items.reduce((s, i) => s + i.price, 0);
// 2. Direct Database Persistence
db.query("INSERT INTO orders VALUES (?)", [order.id, total]);
// 3. Presentation / Email
emailClient.send(order.userEmail, "Your receipt: $" + total);
}
}Couples business math, raw SQL queries, and email transport in a single class. Changes to database schemas or email templates break order calculations.
// 1. Business Math
class OrderCalculator {
calculateTotal(order: Order): number {
return order.items.reduce((s, i) => s + i.price, 0);
}
}
// 2. Persistence Layer
class OrderRepository {
async save(orderId: string, total: number) {
await db.orders.insert({ orderId, total });
}
}
// 3. Notification Service
class EmailNotifier {
async notify(email: string, total: number) {
await emailClient.sendReceipt(email, total);
}
}Each class has exactly 1 reason to change. Unit testing business math requires 0 database or email mocks.