Oplec said:
Would any of you mind offering a design for implementing 12.7[2] that
complys with Mr. Stroustrups constraints? I have provided the source code to
my particular solution in hopes that it might be used as a basis for a quick
solution that is more proper than my own.
I read the exercise again and it made more sense. I was getting hung up on
the purpose of the contact points for something like a line drawn at an
angle. A colleague suggested that the contact points could be the points you
would "grab" in a drawing editor to modify the shape. (The same colleague
then complained that I "always have to understand every detail". Apparently,
I ask too many questions instead of just accepting what's written.)
Although the contact points seem to overly complicate the line class for
this exercise, they are useful for a rectangle, since you will have other
shapes attached to the corners when drawing something like a house.
I've had a look at your code, and it's fine. The reason the exercise had a
Window::draw became clear when I saw your code, i.e., that the window needs
to keep track of its current position by using the se() point of the shape.
Alternatively, the shape could pass its se() to the window instead after
drawing. You could probably have an argument over which class has the
responsibility for doing this, but it's certainly simpler having the window
do it.
The window's then calling the shape's draw by passing a reference to itself
is how I'd envisaged it. Really, there's no other reasonable choice once
you've called w.draw(shape).
I can't find anything to criticize in your design. It's as good as it can be
in my opinion. I can't see anything much wrong with the implementation
either. One thing I'd suggest is making Shape a class rather than a struct.
Although the struct works, it is most unconventional to have an abstract
class such as Shape declared as a struct. Structs are usually used only as
POD ("plain old data") types. 'Shape' being a struct would probably confuse
people.
DW