From the course: C++ Design Patterns: Structural

Unlock the full course today

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

Challenge: Drawing shapes

Challenge: Drawing shapes - C++ Tutorial

From the course: C++ Design Patterns: Structural

Challenge: Drawing shapes

(bouncy upbeat music) - [Instructor] Here's the C++ project that allows us to draw shapes. The design is based on classes implementing the abstract Shape class which is a single draw method. The concrete classes are Circle, Rectangle, and Triangle. They contain the properties that describe their shapes such as Radius for Circle, Width and Height for Rectangle, and Side lengths for Triangle. These classes also implement the draw method responsible for drawing the shapes on the screen. Now there's just a dummy cout statement, but implementing the actual drawing code is out of scope for this demo. We can draw individual shapes by creating objects of the respective classes and calling their draw methods as demonstrated in the main function. At this point, our design works flawlessly. But what if you want to draw a complex shape such as a house? The design lacks the capability of representing and manipulating complex…

Contents