67. Validating passwords

The problem described here is a typical case for the decorator pattern. This design pattern allows adding behavior to an object without affecting other objects of the same type. This is achieved by wrapping an object within another object. Multiple decorators could be stacked on top of each other, each time adding new functionality. In our case, the functionality would be validating that a given password meets a particular requirement.

The following class diagram describes the pattern for validating passwords:

The implementation of the pattern, as described in the diagram, is as follows:

class password_validator{

Get The Modern C++ Challenge now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.