Jump to content
xisto Community
Sign in to follow this  
bluefish1405241537

Inheritence Paradox Creating a hierarchy of polygons

Recommended Posts

First of all, this is mostly theoretical and does not really relate to what I am doing right now.I am thinking of a hierarchy of shapes. Part of the hierarchy is shown here:SquareRectangle / RhombusParallelogramTrapezoidConceptually, each item on the hierarchy should inherit from those below it. After all, all squares are rectangles but not all rectangles are squares. Squares should be able to be used where a rectangle or rhombus is required, and so on.However, in practice, when it comes to implementing these classes, each item would inherit from those above. A rectangle requires more details in its implementation than a square. For example (where a member prefixed by + is not inherited):Square (+width)Rectangle (width, +height) / Rhombus (width, +angle)Parallelogram (width, height, angle)Trapezoid (width, +width2, height, angle)The paradox is, the conceptual part leaks into implementation when you have pointers of references to base classes. But we cannot ignore the fact that if we used that method, our inheriting classes would be ignoring most of the members of the base classes and not creating any of their own.The only practical solution to this problem that I could see would be having each class define all the variables it needs, as well as its base classes variables. This would work, but it would present problems, e.g. how to change a shape when more than one variable needs to be redefined. You could just provide a copy constructor and members to fetch values, and keep all values private.Ideas? Insight?

Share this post


Link to post
Share on other sites

Interesting thought, in geometry we go from the abstract down to the completely defined. In computer science we think of a different form of abstract. The definitions get muddled in the comparisons leading to some off the bat ideas and confusion, its interesting how terms in related field's don't easily meld together. A square is a very basic shape, where a trapezoid is not a basic shape, so your really going in math we are going from unbasic -> basic, instead of the cs basic -> unbasic. Thanks for the thought.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.