|
|
|
|
![]() ![]() |
Dec 16 2006, 06:34 PM
Post
#1
|
|
|
Member [ Level 2 ] 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? |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 5th December 2008 - 12:13 AM |