0
0
LLDsystem_design~20 mins

Program to interface not implementation in LLD - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Interface Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why prefer programming to an interface rather than an implementation?

Imagine you want to build a remote control for different TV brands. Why is it better to design the remote control to work with a general TV interface instead of a specific TV brand's implementation?

ABecause programming to an interface allows the remote to work with any TV brand that follows the interface, making it flexible and easy to extend.
BBecause programming to an implementation makes the remote control faster and more efficient for one TV brand only.
CBecause programming to an interface requires more code and is harder to maintain.
DBecause programming to an implementation avoids the need for interfaces and reduces complexity.
Attempts:
2 left
💡 Hint

Think about how many different TV brands you want your remote to control without changing the remote itself.

Architecture
intermediate
2:00remaining
Identify the correct design for a payment system using program to interface principle

You are designing a payment system that supports multiple payment methods like credit card, PayPal, and bank transfer. Which design best follows the 'program to interface, not implementation' principle?

ADefine a PaymentMethod interface with a pay() method, and implement this interface for each payment type. The system uses PaymentMethod references only.
BWrite separate classes for each payment type and call their specific methods directly without any common interface.
CUse a single PaymentProcessor class that contains all payment logic for every payment type inside it.
DCreate a PaymentMethod abstract class but use concrete classes directly in the system without interface references.
Attempts:
2 left
💡 Hint

Think about how the system can add new payment types without changing existing code.

scaling
advanced
2:00remaining
Scaling a notification system using program to interface principle

You have a notification system that sends messages via email, SMS, and push notifications. To scale and add new notification types easily, which approach best applies the 'program to interface' principle?

ACreate separate classes for each notification type but do not use a common interface or base class.
BHardcode the logic for each notification type inside a single NotificationService class.
CCreate a NotificationSender interface with a send() method. Implement this interface for each notification type. The system uses NotificationSender references to send messages.
DUse concrete classes directly and call their methods without any interface abstraction.
Attempts:
2 left
💡 Hint

Consider how adding a new notification type affects existing code.

tradeoff
advanced
2:00remaining
Tradeoffs when programming to interface instead of implementation

What is a common tradeoff when choosing to program to an interface rather than a concrete implementation?

AIt always improves performance but makes the code harder to understand.
BIt may introduce slight performance overhead due to indirection but improves flexibility and maintainability.
CIt reduces code size significantly but limits future extensions.
DIt removes the need for testing because interfaces guarantee correctness.
Attempts:
2 left
💡 Hint

Think about the cost of abstraction versus benefits.

component
expert
3:00remaining
Design component interaction using program to interface principle

You are designing a modular logging system where different modules can log messages to various outputs (console, file, remote server). How should components interact to follow the 'program to interface' principle?

AModules implement their own logging logic without using shared interfaces or components.
BModules directly instantiate concrete logger classes and call their log methods.
CModules send log messages to a global logging function without any interface abstraction.
DDefine a Logger interface with a log(message) method. Modules depend only on Logger interface references, and concrete loggers implement this interface.
Attempts:
2 left
💡 Hint

Consider how modules can switch logging outputs without changing their code.