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: Drawing shapes - C++ Tutorial
From the course: C++ Design Patterns: Structural
Solution: Drawing shapes
(upbeat music) - [Instructor] Hello, and welcome back. In this video, I'll show you the design I have come up with for drawing aggregate shapes using the composite design pattern. So we've got our initial code base with the abstract shape class and the concrete shape classes circle, rectangle, and triangle. To make it possible to create aggregate shapes, I added a new class, composite shape. The composite shape class implements the shape interface. Let's have a closer look at the design of this class. The private data member of the class is a vector of shape objects. The add shape and remove shape methods allow us to add or remove individual shapes from the composite shape. And finally, the draw method iterates through this vector and draws each individual shape. The main function shows how to draw a composite shape. First, we create some primitive shapes: a circle, a rectangle, and a triangle. Next, we create an…