Laboratory 8: Design Patterns
I. File Accessing
II. 1999 Winter Project
This project was given in the Winter semester of 1999 and it involves quite a
few design patterns and it also touches on some advanced techniques. The outline
of the model was provided for the students but the bonus questions go far beyond
elementary object oriented modeling. Understanding how the pieces are put
together and how the model provides flexibility and maintainability is
important. This project involved virtually all basic steps and techniques of
basic object oriented design.
Model Solution
Drawing Bonus
The strategy is to find one point on the perimeter of the figure
which is inside. Once we have that point p then we can
recursivelly halve the distance between p and o (towards
p) until it is inside the figure. To find p, we can
use one of the corners, or if there is no corner inside we can find two
intersecting points and use their median. Check out shape::inside,
shape::intersects and shape::find_in. It is the same for
the ellipse, after all, it is drawn with lines between points. There is
another case, maybe the figure totally surrounds the canvas and the middle
is still not in. In that case, you should check that at least one of the
points have to have a mapped x coordinate which is less than 0,
one which is larger than width, one mapped y coordinate
less tan 0 and one larger than height
All of the above is only true for convex shapes, but that is
all what we have.
These files test if your bonus implementation is OK:
e1.pic // ellipse test
t1.pic // triangle test
r1.pic // rectangle test
If your (bonus) implementation does not work, you will only see lines.
Parameter Passing, Recursion, ....
You would have to build a new hierarchy (check out statement ),
which would store the actual statements of the user defined figure, puts
them into a figure_descriptor and registers it in a symbol_table....
Test Files:
