From the course: C++ Design Patterns: Structural

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Challenge: Enhancing a design using the Bridge pattern

Challenge: Enhancing a design using the Bridge pattern - C++ Tutorial

From the course: C++ Design Patterns: Structural

Challenge: Enhancing a design using the Bridge pattern

(upbeat music) - [Instructor] And here's the challenge for this module. Implement a program that creates different types of vehicles, like cars, trucks, bikes, with different types of engines, such as gas, electric, hybrid. Without the bridge pattern, the program would require a class hierarchy for each type of vehicle and engine, such as car/gas, car/electric, truck/gas, truck/electric, and so on. Instead of this design, you can use the bridge pattern to design an interface-based solution that supports various combinations of vehicles and engines. You will need an abstract interface for each of the two main concepts, IVehicle and IEngine. IEngine should define a pure virtual start method, whereas IVehicle should expose a public drive method and an abstract drive vehicle method. The drive method will call the start method of a concrete IEngine instance, followed by a call to the drive vehicle method. Next, you'll…

Contents