Javatpoint Logo

how interface is loose coupling

By: m.kris*** On: Fri Feb 22 10:31:21 IST 2013     Question Reputation0 Answer Reputation0 Quiz Belt Series Points0  0Blank User
how interface is loose coupling and abstract class is tight couplingUp0Down

 
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.
Image Created0Down

By: [email protected] On: Fri Feb 22 14:40:31 IST 2013 Question Reputation0 Answer Reputation147 Belt Series Points0 147User Image
Are You Satisfied :0Yes1No