I am new to C++ and hence need some help. Here is the code:
class InterfaceVehicle
{
virtual int door() = 0;
virtual int seats() = 0;
virtual int enginepower() = 0;
}
class minicar: public InterfaceVehicle
{
int door () {return 4;}
int seats () {return 2;}
int enginepower () {return 10;}
}
class bigcar: public InterfaceVehicle
{
int door () {return 4;}
int seats () {return 5;}
int engine () {return 20;}
}
class truck: public InterfaceVehicle
{
int door () {return 2;}
int seats () {return 1;}
int engine () {return 50;}
}
I have an interface base class named Vehicle and three different classes that implements all the functions of the interface class. Here i want to avoid the same implementation of the door function. I got some suggestions to have a new class that implements this door function and this class will be aggregated into bigcar and minicar. This way i can avoid this copy paste implementation of door(); I like this idea!
Can some please give an example on how i can implement that? I read a lot about aggregation but did not understand how to implement that in my case.