Complete the code to declare the high-level module depending on abstraction.
class HighLevelModule: def __init__(self, [1]): self.service = service
The high-level module should depend on an abstraction, here named service, not a concrete implementation.
Complete the code to define an abstraction for the service.
class [1]: def operation(self): pass
The abstraction is usually an interface or abstract class, here named ServiceInterface.
Fix the error in the code to make the low-level module implement the abstraction.
class LowLevelModule([1]): def operation(self): return "Low level operation"
The low-level module must implement the abstraction ServiceInterface to follow the Dependency Inversion Principle.
Fill both blanks to complete the high-level module method calling the service operation.
class HighLevelModule: def __init__(self, service): self.service = service def execute(self): return "High level " [2] self.service.[1]()
The high-level module calls the operation method of the service. The '+' is used here to concatenate or combine the result if needed.
Fill all three blanks to complete the dependency injection and usage in the client code.
service = [1]() high_level = HighLevelModule([2]) result = high_level.[3]()
The client creates an instance of the low-level module, injects it into the high-level module, and calls the execute method.