This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Question on coupling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question on coupling" Watch "Question on coupling" New topic
Author

Question on coupling

Thyagarajan Ramanujam
Greenhorn

Joined: Mar 24, 2008
Posts: 25
Hi,

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

Thanks
Tom Johnson
Ranch Hand

Joined: May 11, 2005
Posts: 142
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


<a href="http://faq.javaranch.com/java/UseCodeTags" target="_blank" rel="nofollow">Use Code Tags!!</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on coupling
 
Similar Threads
ServiceLocator Pattern
Coupling
Coupling question
Can anyone explain what is coupling and cohesion with live examples and coding.
example of cohesion & coupling