I’m currently working in C#, and I have a base class (bullet) that is required to have a variable and subsequent getter (image) because another class expects that behavior (powerup) in order to display properly. Bullet will then be extended to make many different bullets with varying behavior. however, every bullet extension class needs only one image per class (not per instance) because it will never need to change between bullets of similar class, and there will be hundreds of them on screen, so space is an issue. ie, I need an object in a base class, that is then static in extensions from that class. Is there any way to create this in C#, and if not, out of curiosity, any other object oriented language?
Many Thanks
edit:
for example:
class bullet{
public Image Level
{
get { return image; }
set { image = value; }
}
}
class spiralBullet : bullet{
static var image = "spiralbullet";
}
class largeBullet : bullet{
static var image = "largebullet";
}
except somehow, the getter returns the correct static image for each class
Define an abstract property Getter on your base class.
In the derived class, have a private static Image field.
Override the abstract property Getter and return your static image field.
Alternatively, if the Image is a simple hard-coded value:
The advantage here, if it’s suitable, is that the value “Square” exists in a code segment, not a data segment, and is ‘static’ (or shared) by definition.