On 6 Oct 2005 17:24:29 -0700, "Merlin" <merlin2769@hotmail.com> wrote:
[color=blue]
>Design Problem
>===============
>
>Would appreciate any help or suggestion on this design issue. I have
>spent a great deal of time and effort for an elegant solution but it
>seems I am not getting anywhere...
>
>I have simplified my design problem to the following:
>
>Consider the following classes:
>Entity, Point, Polygon, Shape
>
>Entity is the base class of Point, Polygon and Shape
>
>Point is obvious
>Polygon is defined using a set of points
>Shape is a "set" of polygons BUT it will have one outside polygon and
>zero or more inside polygons (ie. holes)[/color]
Not sure about this, but it sounds like you are eliminating certain
kinds of shapes from your Shapes (e.g. circles, ellipses, Moebius
strips, etc.) Usually, "Shape" is abstract and doesn't know how it
will be drawn.
[color=blue]
>If I apply the composite pattern, I can make Entity to be the component
>and Point will be a leaf. [There are other leaves in my original
>design. Remember this is a simple example][/color]
As to the design, a Circle or Ellipse only needs to know just a few
points. A circle can be described by one point (i.e. the center) and a
length (i.e. the radius). The ellipse needs a few more data to
describe its circumference.[color=blue]
>
>Then Polygon will be a composite and so will Shape.
>The datastructure to use for the polygon could be an array or a list.[/color]
Polygon would indeed be described sufficiently as an array of points.
Since the order of the points appears to be important, I would use a
vector, and not a list, to describe them...unless you need to add or
subtract certain points very fast, in which case std::list<> might be
more appropriate.
[color=blue]
>However, the datastructure to use for Shape is debatable. Unlike a
>polygon where its points can happily reside side by side in an array or
>a list, the polygons in a shape have a hierarchial relationship. The
>outside polygon is the parent of the inside polygons. It therefore
>seems reasonable to use a tree data structure in Shape to store the
>polygons. GOF suggest using different data structure to store the
>children of a composite and Shape seems to offer an object where a tree
>would be appropriate.[/color]
[rest snipped]
Don't get caught up in the data representation until you have decided
how you will use your structures. Maybe an array of points is not even
necessary?
--
Bob Hairgrove
NoSpamPlease@Home.com