From the course: C++ Design Patterns: Structural
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Solution: Enhancing a design using the Bridge pattern - C++ Tutorial
From the course: C++ Design Patterns: Structural
Solution: Enhancing a design using the Bridge pattern
(bright upbeat music begins) - [Instructor] Welcome back. How did you design your solution? Here's how I approached this challenge. First, I created two abstract interfaces, IEngine and IVehicle. IEngine defines a pure, virtual start method. This method will be implemented by all concrete engine classes. IVehicle defines the public drive method and the pure virtual drive vehicle method. Drive calls the start method of a concrete IEngine instance, represented by the private m_engine member variable, which is initialized in the constructor. Then, it calls drive vehicle, which is also a pure virtual method, to be implemented by each concrete vehicle class. The IEngine and IVehicle classes are now ready to be extended by concrete implementations. For IEngine, I created three classes, GasEngine, ElectricEngine, and HybridEngine. Their corresponding start method implementations will print out some text to the console,…