Code AnalysisIntermediate 60s
Violated LSP with strengthened precondition
class Account {
withdraw(amount: number): void {
// allows amount >= 0
}
}
class PremiumAccount extends Account {
withdraw(amount: number): void {
if (amount < 100) throw new Error('min 100');
// ...
}
}
// client code:
function drain(a: Account, amt: number) { a.withdraw(amt); }
drain(new PremiumAccount(), 20); // throws
Which principle is violated and why?
Think you can answer under pressure?
Get matched and answer live questions in 3-minute 1v1 battles. Elo ranking, badge tiers and bragging rights on the line.