I have declared an ISpaceObject
interface in my 4X game.
I also have declared the abstract Vehicle
and StellarObject
classes that implement that interface.
Each of those abstract classes has subclasses inheriting from it (e.g. Ship
, Base
, Fighter
for Vehicl
and Planet
, Star
, Storm
for StellarObject
).
I want to be able to display icon and portrait pictures for each type of object.
I have implemented graphics code (e.g. an Icon
property) in the individual classes, but it's specific to WinForms and I want to write a WPF port of my app.
I don't want to have a WinFormsIcon
, WpfIcon
, etc. property in each of my classes; that would be kind of silly, and I'm sure putting the WinForms code in there in the first place was a mistake.
How do I do parallel behaviors like this without resorting to code like the following:
if (o is Ship)
// get ship graphic
else if (o is Base)
// get base graphic
else if (o is Fighter)
// get fighter graphic
etc?