Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Inheritence Paradox, Creating a hierarchy of polygons
bluefish
post Dec 16 2006, 06:34 PM
Post #1


Member [ Level 2 ]
Group Icon

Group: Members
Posts: 71
Joined: 16-December 06
Member No.: 18,419



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:
Square
Rectangle / Rhombus
Parallelogram
Trapezoid

Conceptually, 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?
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Creating A Game In Rpg Maker 2000/2003(18)
  2. 3ds Max Tutorial #2-creating Reflective Materials(1)
  3. Creating You Own Game In RPG Maker 2000/2003(12)
  4. How Do I Create And Write To Files?(4)
  5. Creating Tooltips(7)
  6. Permission Denied In Creating A Directory(6)
  7. Need A Tutorial On Creating A Font(5)
  8. Creating Irc Chat Room...(10)
  9. Creating Your Own Simple But Effective Site(26)
  10. Creating Windowsxp Bootable CD(2)
  11. Creating Executable Jar Files(9)
  12. Creating New Process Under Alternate Credentials (createprocessasuser)(6)
  13. Creating Flash Image/slideshow(2)
  14. Help Creating A Browser-based Rpg(5)
  15. C# Tutorial : Lesson 7 - Creating Value Types & Reference Types - Part II(1)
  1. Best Software For Creating Games(9)
  2. Creating A Fantastic Fantasy Night Sky In Photoshop(4)
  3. Creating Interactive Pdf Documents(2)
  4. Creating Dll With Delphi(0)
  5. Altiris Deployment Server: Creating Boot Disks (remote)(2)
  6. Creating Your First Application(1)
  7. Help Me Creating My Text Based Game.(2)
  8. Creating Bootable Cds(1)
  9. Creating Links With Quotes (")(2)
  10. 3d Game Creating Thing(1)
  11. Creating A Php Login Script(3)
  12. Creating An Mmo(3)
  13. Creating A Template Engine(1)


 



- Lo-Fi Version Time is now: 5th December 2008 - 12:13 AM