From the course: C++ Design Patterns: Structural

Unlock the full course today

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

The Bridge pattern in action

The Bridge pattern in action - C++ Tutorial

From the course: C++ Design Patterns: Structural

The Bridge pattern in action

- [Instructor] As we've seen, this design has a severe problem. Adding new features requires us to create new classes for each variation. The bridge design pattern helps us solve this problem. We'll start by separating the design into two distinct hierarchies. One for the features that are common across all implementation classes, and one for the features specific to each variation. So what's common across all these classes? The code logic of sharing text messages. And what's different? The way the messages are prepared for sharing and handled. We have plain messages, encrypted and expiring messages. Thus, we can introduce two abstractions. ITextHandler for message preparation and handling, and ITextSharer for the core message sharing functionality. I start by defining the ITextHandler abstract class. It is a single pure virtual method prepare message, let's make it public, that takes a plain text string as an…

Contents