From the course: C++ Design Patterns: Structural

Unlock the full course today

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

Exploding class hierarchies

Exploding class hierarchies - C++ Tutorial

From the course: C++ Design Patterns: Structural

Exploding class hierarchies

- I've created a C++ project to illustrate the design problem we're trying to solve with the bridge pattern. The design uses a class hierarchy to represent the different ways we can share text. IText Share is an abstract class that declares a pure virtual method, share text. Email share and SMS share are complete implementations of IText Share used to share text messages. For the sake of this demo the share text methods simply print the text passed as an argument to the console. A new feature request is to add an encryption mechanism for the messages before they are shared. A naive approach would be to add two subclasses, one for each type of text sharing. Email share encrypted and SMS share encrypted. The subclasses use a simple X or algorithm to obfuscate the messages and call their super classes share text methods to complete the task. This design is fine if we only have two types of messages but what happens when we need…

Contents