• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on coupling

 
Thyagarajan Ramanujam
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can someone explain how the usage of interfaces can reduce coupling?

Thanks
 
Tom Johnson
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a class has a reference to an interface (rather than a concrete implementing class), it does not need to know anything about the actual object passed in and it allows you to pass in any class that implements the specified interface so its really flexible.
As an example, the List interface. If you write a bunch of methods that accept a parameter of type java.util.List, you can pass in any type of list like ArrayList or LinkedList and you dont need to change the methods themselves. However, if defined all the methods with ArrayList instead and then in two weeks time you decided a LinkedList performed better, you would need to change each method to accept LinkedList rather than ArrayList.
hope this helps
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic