C Shape Hierarchy found info on this very site httpwwwcheg
C++ Shape Hierarchy! ---> found info on this very site -> http://www.chegg.com/homework-help/project-polymorphic-screen-manager-using-shape-hierarchy-dev-chapter-21-problem-14e-solution-9780133061567-exc
21.14 (Project: Polymorphic Screen Manager Using Shape Hierarchy) Develop a basic graphics package. Use the Shape hierarchy implemented. Limit yourself to two- dimensional shapes such as squares, rectangles, triangles and circles. Interact with the user. Let the user specify the position, size, shape and fill charaiersio be, ussed in drawineach shape. The user can specify more than one of the same shape. As you create each shape, place a Shape*pointer to each new Shape object into an array. Each Shape class should now have its own draw member function. Write a polymorphic screen manager that walks through the array, sending draw messages to each object in the array to form a screen image. Redraw the screen image each time the user specifies an additional shape.Solution
The code below illustrates a Simple shape object which is a line, note that this object represents a leaf.
The code below illustrates a complex object, which is a rectangle object. This object represents a Composite.
The code below illustrates a more complex shape object which also represents a composite
The code below illustrates the Graphics Editor Driver class which represents the client. Note how the client of the composite pattern deals with all Shape objects uniformly despite the fact that some of the shapes are leafs while others are branches.
package composite; /** * * Line is a basic shape that does not support adding shapes */ public class Line implements Shape { /** * Create a line between point1 and point2 * @param point1X * @param point1Y * @param point2X * @param point2Y */ public Line(int point1X, int point1Y, int point2X, int point2Y) { } @Override public Shape[] explodeShape() { // making a simple shape explode would return only the shape itself, there are no parts of this shape Shape[] shapeParts = {this}; return shapeParts; } /** * this method must be implemented in this simple shape */ public void renderShapeToScreen() { // logic to render this shape to screen } } } |
