From the course: C++ Design Patterns: Structural

Unlock the full course today

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

Solution: Refactor using the Adapter pattern

Solution: Refactor using the Adapter pattern - C++ Tutorial

From the course: C++ Design Patterns: Structural

Solution: Refactor using the Adapter pattern

- [Instructor] Welcome back. How did it go? Did you figure out how to design an adapter for the VirtualDrive class? Let's take a look at my solution. I chose to design a class adapter as it requires less code. I named the adapter class VirtualDriveAdapter. It inherits publicly from cloud storage to provide the expected interface, and privately from the VirtualDrive class to delegate requests to it. uploadContents forwards the request to uploadData. However, I had to implement a helper method for generating the unique identifier, the extra argument required by the uploadData method. Here's our private helper method, generateUID. So uploadContents forwards the request to uploadData by passing in the content and this unique identifier. The getFreeSpace method should return the free available space. But as you know, the VirtualDrive class exposes a method that returns the usedSpace. Thus, I subtracted the usedSpace…

Contents