Complete the code to fix the Single Responsibility Principle violation by separating concerns.
class UserManager: def create_user(self, user_data): # code to create user pass def [1](self, user): # code to send welcome email pass
The method send_welcome_email should be moved to a separate class to follow Single Responsibility Principle.
Complete the code to fix the Open/Closed Principle violation by allowing extension without modification.
class Report: def generate(self, report_type): if report_type == 'pdf': return self.generate_pdf() elif report_type == 'csv': return self.generate_csv() def generate_pdf(self): pass def generate_csv(self): pass class [1](Report): def generate_excel(self): pass
Creating a new subclass ExcelReport allows adding new report types without modifying the existing Report class, following Open/Closed Principle.
Fix the error in the code violating the Liskov Substitution Principle by correcting the method signature.
class Bird: def fly(self): pass class Penguin(Bird): def [1](self, speed): # Penguins cannot fly, so this method should not accept parameters pass
The subclass method fly must have the same signature as the superclass method to satisfy Liskov Substitution Principle.
Fill both blanks to fix the Interface Segregation Principle violation by splitting interfaces.
class [1]: def print_document(self, document): pass class [2]: def scan_document(self, document): pass
Splitting into separate Printer and Scanner interfaces avoids forcing clients to depend on methods they do not use.
Fill all three blanks to fix the Dependency Inversion Principle violation by introducing abstractions.
class [1]: def connect(self): pass class Database: def __init__(self, [2]): self.connection = [3] def query(self): self.connection.connect()
Using an abstraction ConnectionInterface and depending on it via the parameter connection in Database class follows Dependency Inversion Principle.