I have a class "Car" and a subclass "LuxuryCar" derived from "Car". I also have a class "Radio" and a subclass "SatelliteRadio" derived from "Radio".
I would like the Car to maintain a reference to a Radio. And I would like a LuxuryCar to maintain a reference to a SatelliteRadio.
When instantiating a LuxuryCar object, it creates a reference to a SatelliteRadio. SatelliteRadio has available all the methods of Radio and a method unique to SatelliteRadio. But since LuxuryCar is a subclass of Car, it by default has a reference to a Radio (inherited from the Car class) that I don't really need. And the constructor of the base class Car instantiates a Radio I don't need (I only want a SatelliteRadio). I do need the methods of Car.
I could instantiate the Radio and SatelliteRadios outside of the Car and LuxuryCar classes. But I would still have a reference to Radio in LuxuryCar that I don't really want.
My gut tells me this is not correct and there is a better way to design this. I would like to maintian the inheritence relationship between the cars and the radios. And I want to be able to instantiate both a Car and LuxuryCar if I want.
Any help or thoughts would be appreciated.
Thanks,
Adam
class Car
{
public:
Car();
virtual ~Car();
virtual Start();
provate:
Radio* theRadio;
};
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.