I have been told that using instanceof like in the code below is bad practice as it becomes repetitive and makes extension hard. I'm pretty new to Java though and don't see straight away what my alternatives are, what would you recommend I do to get rid of instance of and abstract the code?
void moveit(Vehicle car) {
if(car instanceof Volvo240){
volvoPoint.x = (int) car.getXCoordinate();
volvoPoint.y = (int) car.getYCoordinate();
}
if(car instanceof Scania) {
scaniaPoint.x = (int) car.getXCoordinate();
scaniaPoint.y = (int) car.getYCoordinate() + 100;
}
if(car instanceof Saab95) {
saabPoint.x = (int) car.getXCoordinate();
saabPoint.y = (int) car.getYCoordinate() + 200;
}
repaint();
}