0
0
LLDsystem_design~20 mins

Liskov Substitution Principle in LLD - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
LSP Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Liskov Substitution Principle (LSP)

Which of the following best describes the Liskov Substitution Principle in system design?

ABase classes must be replaceable by their derived classes without altering the correctness of the program.
BBase classes must never be extended by derived classes to avoid complexity.
CSubclasses should always add new methods instead of modifying existing ones.
DDerived classes can override base class methods with completely different behaviors.
Attempts:
2 left
💡 Hint

Think about substituting objects in a program without breaking it.

Architecture
intermediate
2:00remaining
Applying LSP in Class Hierarchies

Consider a class hierarchy where a Rectangle class has a method setWidth and setHeight. A subclass Square overrides these methods to keep width and height equal. Which problem does this violate according to LSP?

ANo violation; LSP only applies to interfaces, not classes.
BSquare perfectly follows LSP because it inherits Rectangle methods.
CRectangle violates LSP because it allows width and height to be set separately.
DSquare cannot be substituted for Rectangle because it changes expected behavior of setting width and height independently.
Attempts:
2 left
💡 Hint

Think about whether the subclass changes the expected behavior of the base class methods.

scaling
advanced
2:30remaining
Scaling Systems with LSP-Compliant Components

When designing a large-scale system with multiple service components, how does adhering to LSP help in scaling and maintaining the system?

AIt forces all components to be identical, reducing flexibility in scaling.
BIt ensures components can be replaced or extended without breaking existing integrations, easing scaling and maintenance.
CIt requires rewriting all components when scaling to maintain consistency.
DIt limits the number of components to avoid complexity.
Attempts:
2 left
💡 Hint

Consider how substitutability affects system upgrades and extensions.

tradeoff
advanced
2:30remaining
Tradeoffs When Enforcing LSP Strictly

What is a common tradeoff when strictly enforcing LSP in a complex system design?

AIt forces all subclasses to have identical code, causing duplication.
BIt always increases system complexity and bugs.
CIt may limit the ability to optimize subclasses for specific cases, reducing performance gains.
DIt eliminates the need for interfaces and abstract classes.
Attempts:
2 left
💡 Hint

Think about balancing design purity and practical optimizations.

component
expert
3:00remaining
Identifying LSP Violation in Component Interaction

Given a payment processing system where a PaymentProcessor interface defines a method processPayment(amount). A subclass CryptoPaymentProcessor overrides this method but throws an exception if the amount is below a minimum threshold, unlike the base implementation which accepts all amounts. What is the impact of this on LSP?

ACryptoPaymentProcessor violates LSP because it changes the expected behavior by throwing exceptions for inputs accepted by the base class.
BCryptoPaymentProcessor follows LSP because it extends the base interface and adds validation.
CThere is no impact on LSP since exceptions are allowed in subclasses.
DLSP is not applicable to interfaces, only to concrete classes.
Attempts:
2 left
💡 Hint

Consider whether the subclass can be used anywhere the base class is expected without causing errors.