I would like to ask something about an issue i have. Lets say we have an interface called Vehicle.
Then we have a class that implements this interface called Car. Then another one called Bicycle.
Now the whole code uses these two objects (Car, Bicycle) and whenever needed interface Vehicle.
What if now i want to add a new attribute to Car class and due to this change also modify some of its methods. For example i can extend Car with a class called Car2. But now if i want to make use of Car2 in the code i will have to rewrite every single method and class that uses Car to a new class that will use Car2.
For example a method that does not belong to Car class.
int checkSpeed(Car c) {
speed = c.attributeX * 100
}
Now i want this method to be able to accept Car2 also and change the way it calculates its speed. Do i need to rewrite the class and method or is there an easier way to do it?
Keep in mind that i dont want to completely modify Car, i just want to have both Car and Car2 and use them on demand in the same classes without having to rewrite all of them.
Thanks!