From the course: C++ Design Patterns: Structural

Unlock the full course today

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

Implementing an object adapter

Implementing an object adapter - C++ Tutorial

From the course: C++ Design Patterns: Structural

Implementing an object adapter

- [Instructor] In this video, I'll show you how to integrate the legacy component class in our design using an object adapter. An object adapter works by wrapping the adaptee, in this case, the legacy component in an adapter class that implements the target interface, our component abstract class. Thus the adapter exposes the same interface as the component class, making it compatible with our design. However, internally, the adapter delegates the call to its adaptee, calling the legacy component objects go method. Let's see how this works in practice. First, I'll create a new class called legacy adapter that inherits from component, class LegacyAdapter and it should inherit publicly from component. This adapter class needs to wrap the legacy component object, so I'll add a data member of type legacy component. I'll make it a private field, as this adapter object will be the only one to access it. We don't want to…

Contents