I am working on low level design of cab booking type of system and feeling stuck at modelling Vehicle in Booking class.I came up with following design.
Class Vehicle
{
}
Class Car extends Vehicle
{
}
Classs Bike extends Vehicle
{
}
Class Auto extends Vehicle
{
}
Class Booking
{
int number;
...
....
Vehicle Vehicle;
VehicleType type;
...
...
}
enum VehicleType
{
CAR,
BIKE,
AUTO
}
Now to see, which vehicle is used for booking, we can see the VehicleType from booking and then typecast the vehicle to that object(CAR,BIKE,AUTO).Is it a bad way model?
In general, if we have a reference to parent, and we want to know specific child class which is holds,is this a good way to do?Are there alternate approaches ?
Aucun commentaire:
Enregistrer un commentaire