2

I'm trying to polish up by database design skills. I've been working through a few IT-related puzzles today, most of which have been fairly straightforward. ...And then I came across this supposed 'oldie', which is frustrating the bezeejers out of me.

The premise is that there's an error with the class hierarchy in the diagram below. No further information regarding the nature of the classes/interface is given. I cannot find any logical issue with it. The best I can do is whimper that a point is not technically a shape, but I'd like to think the answer is a little less weaselly than that.

If anyone has any suggestions, I'd love to hear. It really is doing my head in.

Diagram Here

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
user620159
  • 21
  • 1

6 Answers6

1

Perhaps the question is giving us a hint:

No further information regarding the nature of the classes/interface is given.

We have absolutely zero information about the actual scope (i.e. business logic) of the problem. "Shape" could be a mathematical representation to be drawn on a grid. It could be a definition for a game engine modelling program. It could be an indicator of a person's fitness level. Who knows? Each of those variants would require different representations in both class diagrams and a relational data model.

It leaves us only to make assumptions about what might be semantically wrong. However, we can make observations about what might be technically wrong with the diagram itself.

I pose the problem is that the arrows are pointed in the wrong direction. In most class diagrams, inheritance is denoted by the child class having an arrow pointed at the base class.


This answer may seem nonsensical. However, it's actually meant as a jab at the puzzle question itself. In real life, designing anything (databases, class diagrams, whatever) is about taking the business-specific needs of the problem and making the appropriate design decisions. Without knowing anything about the domain, all we can do is make assumptions about what might be semantically wrong with the design, which makes for a rather pointless puzzle problem.
Rob Hruska
  • 118,520
  • 32
  • 167
  • 192
  • Total agreement. It's kinda like some SO questions, where they just don't give you enough for you to come up with the answer they're really looking for. (Not without a few edits, at least.) – Philip Kelley Feb 16 '11 at 20:37
  • For the record, I'm **not** attacking user620159 (who asked the question). S/he's only really asking the question by proxy; my real debate is with the original source of the puzzle. – Rob Hruska Feb 16 '11 at 20:39
  • I'm with you. Database design is related to data models. Is the class diagram we are shown an E-R model or a relational model? If it's a relational model, the arrowheads are at the wrong end. If it's an ER model, the arrowheads should be crow's feet. And there should be a symbol at the junction between lines that indicates "alternative". IIRC, that a semicircle with a flat bottom. – Walter Mitty Feb 16 '11 at 21:29
0

I think the Polygon class is redundant. Is there any special reason why you'd have to separate rectangle and square? Going even further, why differentiate triangle from a rectangle? You could think of both as just a list of points; triangle has three, rectangle has four. And there's the thing you've mentioned yourself; point is not really a shape and maybe that's the most obvious answer you're looking for.

Detra83
  • 271
  • 3
  • 3
  • Polygon is the general shape that includes triangle, rectangle, and square. A polygon has at least three points, but can have more than four. – Gilbert Le Blanc Feb 16 '11 at 18:54
0

I'm stumped too. The only thing I can come up with is that Polygon and Ellipse should be subordinate to Point.

A Polygon is three or more points.

An Ellipse has two focal points.

That would make the Shape interface a list or array of points.

Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111
  • Hi Gilbert. Glad to hear I'm not the only one stumped. I was thinking along the subordinate lines myself a little. The ellipse having only two focal points is a good one; I was thinking along the 'a circle has infinite points' lines, which discouraged me from going along that line of thinking, but focal points makes more sense. Anyhow, thanks for the response. – user620159 Feb 16 '11 at 19:00
0

Your question refers to database design and this is where I see the problem; The class hierarchy is far too deep and in my opinion could be modelled using a single shape class as all share similar properties E.G. all have sides. A circle has one, a triangle has 3 and a rectangle has 4.

As far as the class diagram itself goes I guess it could be argued that point, polygon and ellipse should be interfaces rather than classes.

I also agree that with the other comments about point not being a shape.

Out of interest where has this question originated from?

Benjamin Gale
  • 12,977
  • 6
  • 62
  • 100
0

If I were to look at this from a rigid mathematical perspective, Point and Ellipse/Circle are Conic Sections, and should be in the same class. I don't know that's the magical answer being looked for, but it is one.

Extending that, a Polygon consists of 3-N Lines, which aren't a portion of the data model.

I would agree with the other posters who point out that Circles, Rectangles, and Squares are simply special cases of Polygon, and I would not have broken them out specifically in a relational database model. This may make sense for an object model, but it appears to be overkill for a relational one.

Adam Musch
  • 13,286
  • 2
  • 28
  • 32
0

Given the vague nature of the question, this sounds like it could be a phrasing of the circle-ellipse problem. http://en.wikipedia.org/wiki/Circle-ellipse_problem.

Essentially the error would be defining sub-classes which have invariants that can't be defined in the super-classes:

  • To define a valid square, you have to maintain a height-width ratio that isn't required in a rectangle (in the general case)
  • Ditto (roughly) circle and ellipse

Related discussion at Is deriving square from rectangle a violation of Liskov's Substitution Principle?

Community
  • 1
  • 1
David
  • 2,038
  • 14
  • 11