Complete the code to define a class that uses composition to include a Logger component.
class Application: def __init__(self): self.logger = [1]()
The Application class uses composition by creating an instance of the Logger class inside it.
Complete the code to delegate the log message to the composed Logger object.
class Application: def __init__(self): self.logger = Logger() def log(self, message): self.logger.[1](message)
The Application class calls the log method of the Logger instance to delegate logging.
Fix the error in the code to properly use composition instead of inheritance.
class Logger: def log(self, message): print(message) class Application([1]): def __init__(self): self.logger = Logger()
The Application class should not inherit from Logger but from object to use composition properly.
Fill both blanks to complete the code that shows composition with two components.
class Application: def __init__(self): self.logger = [1]() self.database = [2]()
The Application class composes Logger and Database components by creating their instances.
Fill all three blanks to complete the code that delegates methods to composed components.
class Application: def __init__(self): self.logger = Logger() self.database = Database() def log(self, message): self.logger.[1](message) def save(self, data): self.database.[2](data) def load(self, id): return self.database.[3](id)
The Application class delegates log, save, and load calls to the respective component methods.