Explanation & Logic Summary: The original design incorrectly modeled drivers as buses using inheritance, resulting in multiple bus instances. This violates real hardware behavior. By switching to composition, the bus becomes a shared resource with a single lifetime, while drivers correctly depend on it. This makes ownership, lifetime, and responsibilities explicit and safe.
Firmware Relevance & Real-World Context: In real firmware systems, SPI, I²C, and memory buses are single physical resources shared by multiple drivers. Drivers must coordinate access rather than duplicate hardware abstractions. Composition accurately reflects this relationship and prevents flawed HAL designs that cannot scale to real embedded systems.
Loading...
Input
10 20
30 40
Expected Output
Bus ready
Driver started
Driver started
Bus write: 10 20
Bus write: 30 40
Driver stopped
Driver stopped
Bus stopped