I think if you have to model the differences in polygons with an object model, you are really taking your object model too far down.
I didn't say polygons. I said shapes.
The polygon class should be sufficiently advanced to take arbitrary constraints and handle all properties generically.
Even if I were to be talking about polygons, I still don't agree with that. If you follow such reasoning all the way through, you would never subclass. Instead, you would make you one and only base class more generic.
There shouldn't have to be classes for that, and to a mathematician, rules for a 71-sided polygon with equal angles are scarely different than a quad... the numbers just come out cleaner.
But as I said, I was thinking about shapes, and properties of shapes. For instance, let's talk about simple symmetries. All parallelograms have a rotational point of symmetry (180 degrees around their center). This is not true for all 71-sided polygons - in fact, 71 being odd, there is no 71-sided polygon that has a 180 degree rotational symmetry. Every rectangle has two lines of symmetry - the lines dividing opposite sides, and whatever symmetry a parallelogram has. Every rhombus has two lines of symmetry, but different lines than the rectangle, namely the diagonals. And in addition, it has the symmetries a parallelogram has. Finally, a square has a 90 degree rotational symmetry, a -90 degree rotation symmetry, and the symmetries of a rectangle, and the symmetries of a rhombus.

So, my question remains, what kind of inheritance tree would you use? (And keep in mind, the tree is just part of a bigger picture, there may be hundreds of other shapes as well. If you want to collapse them into one general class, you'll have to do a lot of case statements, and you're back to non-OO programming).

Abigail


In reply to Re: inheritance and object creation by Abigail-II
in thread inheritance and object creation by knew

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.