It really is inheritance that decreases coupling, and multiple inheritance even more so. Interface is Java's way of handling multiple inheritance so they tend to show up in the "write more flexible code" situation. public class Driver { Vehicle myVehicle; public void goFaster(int speed) { myVehicle.speed += speed; } } It really doesn't matter whether Vehicle is a class, an abstract class or an interface. The important step was that your code no longer is hardcoded for Car objects anymore. It will now potentially work with a lot more objects, namely all those objects that may inherit Vehicle (like Car, Bicycle, Boat, Airplane, Spaceship, you name it). Your code has become less coupled and more flexible thanks to abstraction by the way of inheritance. | 0 |
By: [email protected] On: Fri Feb 22 14:40:31 IST 2013 0 147 0 | 147 |
Are You Satisfied :0Yes1No |