0
0
LLDsystem_design~20 mins

Open/Closed Principle in LLD - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Open/Closed Principle Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding the Open/Closed Principle

Which statement best describes the Open/Closed Principle in software design?

ASoftware entities should be open for extension but closed for modification.
BSoftware entities should be open for modification but closed for extension.
CSoftware entities should always be rewritten when requirements change.
DSoftware entities should be neither open for extension nor modification.
Attempts:
2 left
💡 Hint

Think about how to add new features without changing existing code.

Architecture
intermediate
2:00remaining
Applying Open/Closed Principle in Module Design

You have a payment processing system that currently supports credit cards. You want to add support for new payment methods without changing existing payment code. Which design approach follows the Open/Closed Principle?

ACreate a PaymentMethod interface and implement new classes for each payment type, then use polymorphism to process payments.
BAdd new if-else conditions in the existing payment processing class for each new payment type.
CRewrite the entire payment processing class every time a new payment method is added.
DUse global variables to switch payment methods dynamically.
Attempts:
2 left
💡 Hint

Think about how to add new payment types without changing existing code.

scaling
advanced
2:30remaining
Scaling a Notification System with Open/Closed Principle

You have a notification system that sends alerts via email. You want to add SMS and push notifications without modifying existing email notification code. What is the best scalable design following the Open/Closed Principle?

AUse a single Notification class with many conditional statements for each notification type.
BAdd SMS and push notification code directly inside the existing EmailNotification class.
CDuplicate the entire notification system code for each new notification type.
DCreate a Notification interface and implement EmailNotification, SMSNotification, and PushNotification classes; use a factory to instantiate them.
Attempts:
2 left
💡 Hint

Consider how to add new notification types without changing existing classes.

tradeoff
advanced
2:00remaining
Tradeoffs of Strictly Following Open/Closed Principle

What is a common tradeoff when strictly applying the Open/Closed Principle in system design?

AReduced code reuse because everything is written from scratch.
BIncreased number of classes and interfaces, which can make the system more complex to understand.
CDecreased flexibility since existing code must be modified frequently.
DLower maintainability due to tightly coupled components.
Attempts:
2 left
💡 Hint

Think about how adding extensions affects code structure.

component
expert
3:00remaining
Identifying Violation of Open/Closed Principle in Component Design

Given a logging component that writes logs to a file, which change violates the Open/Closed Principle?

Options describe changes to add new logging outputs.

ACreating a new ConsoleLogger class implementing the Logger interface and using it alongside the file logger.
BAdding a new class that implements a Logger interface to support database logging without changing existing file logger code.
CModifying the existing file logger class to add conditional code for console logging.
DUsing a logging manager class that delegates logging to different logger implementations.
Attempts:
2 left
💡 Hint

Look for changes that modify existing code instead of extending it.