Originally posted by jason adam:
When I get all the way down to my Square class (which inherits from Rectangle, which inherits from Parallelogram, which inherits from Quadrilaterial, which inherits from Polygon...), it just seems to me that creating an object of Square is going to take a lot more work than is necessary (having to work all the way up the hierarchy).
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by jason adam:
My print() method (defined as abstract in the Shape class, which is the parent of all the rest) climbs all the way up the chain too, to the TwoDimensionalShapes class, where I define once:
return this.getClass().getName();
Wasn't sure if that was going to work, but it does. This forces me to put a print() method in every class up to the 2D one, each calling super.print(); but this way I can have a Shape[] and know I'll get what I want. Works nice, just wanted to make sure there was not a better way to optimize.
Originally posted by jason adam:
I could just put the name of the class in the literal, would that make more sense than calling super.print() all the way up to TwoDimensionalShape? Thinking I actually should put the implementation in Shape, since both 2D and 3D classes will be using it.
Originally posted by jason adam:
What if I wanted to return a String? So that all the printing is handled in my driver class/program instead of by the actual objects (this is the way I prefer).
Originally posted by jason adam:
Ya know, I never tried calling an abstract method from an implemented method in an abstract class, seems odd. Is this something you see normally?
Originally posted by jason adam:
Another thing, here's my Square and Rectangle code:
[CODE]
public class Rectangle extends Parallelogram
{
.
.
.
public float area()
{
return super.area();
}
public String print()
{
return super.print();
}
The longest recorded flight time of a chicken is 13 seconds. But that was done without this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|