Skip to main content

Practice ยท 2 of 2

Reporter Injection

Create a class Order totals calculator: Order(items) where items is a list of prices. Its total() returns the sum. Add a constructor parameter reporter=None; if provided, total() must call reporter(total_value) once. This is dependency injection for observability.

Difficulty: intermediate

Back to lesson: Practice: Composition Drills