Body and stars
Posted: 26.06.2005, 04:06
Unifying bodies and stars shouldn't take up any extra space.
Body would be an abstract base class, which takes up no memory
class Body {
float getRadius();
}
class Star {
float getRadius() {calculate from spectral type;}
}
class Planet {
float getRadius() {return value};
}
This is an example of the flyweight pattern.
Also in replacing dispatch I was thinking in terms of virtual functions. Using RTTI doesn't get you very much advantage over including a type field.
Body would be an abstract base class, which takes up no memory
class Body {
float getRadius();
}
class Star {
float getRadius() {calculate from spectral type;}
}
class Planet {
float getRadius() {return value};
}
This is an example of the flyweight pattern.
Also in replacing dispatch I was thinking in terms of virtual functions. Using RTTI doesn't get you very much advantage over including a type field.