Thermostat example demonstrates dependency injection principles. Initially, the naive Thermostat class directly creates its dependencies like the TemperatureSensor class. This leads to tight coupling. To decouple the classes, an interface TemperatureSensor is extracted. The dependency is then injected via the constructor rather than created internally. This allows injecting different sensor implementations and makes the Thermostat class more reusable and testable.