Complete the code to define a class that follows the Single Responsibility Principle by having only one reason to change.
class UserProfile: def __init__(self, name, email): self.name = name self.email = email def [1](self): # Save user data to database pass
The method save_to_database fits the class responsibility of managing user profile data. Other options like sending email or generating reports are separate responsibilities.
Complete the code to separate responsibilities by creating a new class for sending notifications.
class NotificationService: def [1](self, message, user): # Send notification to user pass
The method send_notification clearly belongs to a notification service, separating it from user data management.
Fix the error in the class design to ensure each class has a single responsibility.
class UserManager: def save_user(self, user): # Save user data pass def [1](self, user, message): # Send welcome email pass
Sending emails should be handled by a separate class, so this method should be moved out. The method name send_welcome_email shows the responsibility that should be separated.
Fill both blanks to split responsibilities between user data management and logging activities.
class UserManager: def [1](self, user): # Save user data pass class Logger: def [2](self, message): # Log activity pass
save_user belongs to user data management, while log_activity belongs to logging. This separation follows the Single Responsibility Principle.
Fill all three blanks to correctly apply the Single Responsibility Principle by separating user profile, notification, and logging responsibilities.
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
Each method name matches the class responsibility: updating profiles, sending notifications, and logging events. This clear separation follows the Single Responsibility Principle.