0
0
LLDsystem_design~10 mins

Single Responsibility Principle in LLD - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a class that follows the Single Responsibility Principle by having only one reason to change.

LLD
class UserProfile:
    def __init__(self, name, email):
        self.name = name
        self.email = email

    def [1](self):
        # Save user data to database
        pass
Drag options to blanks, or click blank then click option'
Asave_to_database
Bsend_email
Ccalculate_age
Dgenerate_report
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing methods that handle unrelated tasks like sending emails or generating reports.
2fill in blank
medium

Complete the code to separate responsibilities by creating a new class for sending notifications.

LLD
class NotificationService:
    def [1](self, message, user):
        # Send notification to user
        pass
Drag options to blanks, or click blank then click option'
Aupdate_profile
Bsave_user
Csend_notification
Dlog_error
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names that imply saving or updating user data in the notification class.
3fill in blank
hard

Fix the error in the class design to ensure each class has a single responsibility.

LLD
class UserManager:
    def save_user(self, user):
        # Save user data
        pass

    def [1](self, user, message):
        # Send welcome email
        pass
Drag options to blanks, or click blank then click option'
Aupdate_user
Bsend_welcome_email
Cdelete_user
Dlog_activity
Attempts:
3 left
💡 Hint
Common Mistakes
Keeping email sending methods inside the user management class.
4fill in blank
hard

Fill both blanks to split responsibilities between user data management and logging activities.

LLD
class UserManager:
    def [1](self, user):
        # Save user data
        pass

class Logger:
    def [2](self, message):
        # Log activity
        pass
Drag options to blanks, or click blank then click option'
Asave_user
Bsend_email
Clog_activity
Ddelete_user
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing logging methods inside user management class.
5fill in blank
hard

Fill all three blanks to correctly apply the Single Responsibility Principle by separating user profile, notification, and logging responsibilities.

LLD
class UserProfile:
    def [1](self, user):
        # Update user profile
        pass

class NotificationService:
    def [2](self, user, message):
        # Send notification
        pass

class Logger:
    def [3](self, message):
        # Log system events
        pass
Drag options to blanks, or click blank then click option'
Aupdate_profile
Bsend_notification
Clog_event
Ddelete_user
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names that do not match the class responsibility.