From the course: C++ Design Patterns: Structural

Unlock the full course today

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

Solution: Implement a protective proxy

Solution: Implement a protective proxy - C++ Tutorial

From the course: C++ Design Patterns: Structural

Solution: Implement a protective proxy

(bright upbeat music begins) - [Instructor] I hope you had to go at the challenge before checking out my solution. Here's the design of the Protective Proxy class I came up with. Secure storage proxy is derived from storage and exposes the same public interface as the secure storage class, with an additional constructor parameter for the secret code. The class wraps a secure storage instance that gets initialized in the constructor. I used a unique pointer to ensure that the instance gets automatically destroyed when the proxy is deleted. The get contents method contains the access control logic. The proxy requires clients to provide a valid code before granting access to the secure resource. The private authorized method performs a single string comparison, to verify that the provided code matches the secret code, which is 42. If there is a match, the method returns true and get contents forwards the card to the…

Contents