ABSTRACT

Before we leave this section, let’s have some fun. For a shape, one of the first things you think about is “What does it look like?” Acting on that thought by drawing the shape object in a figure window exercises private member variables associated with the shape’s size, scale, and color. The old cliché about a picture painting a thousand words means we can tell at a glance when the values are in the correct range. Drawing the shape also opens the door to many other class considerations. For example, we should update the drawing when the size, scale, or color changes. Encapsulation allows us to easily detect these changes and redraw the figure. Of course, we can’t draw anything until we answer the question “What sort of shape do we draw?” Do we draw a square, a circle, or some random shape? Our current shape class doesn’t include any sort of data to help answer that question. We need to add some member variables, and that forces us to think about generalizing a

draw

member function.