• Post Reply Bookmark Topic Watch Topic
  • New Topic

Coding to interfaces Vs Coding to implementation  RSS feed

 
Padma Priya
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Can anyone explain me why coding to interfaces is good while coding to implementation is bad in java.

Can you explain with the Real world example.

Why does coding to implementation result in tight coupling - This is the point i am not understanding.

Thank you!

 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just seconds ago I explained about exactly these two topics in this question.

Have a look there, you can see Vicinius' code and the improvements in the follow-up posts which is a good example of what you're asking about.
 
Vivek Chulani
Greenhorn
Posts: 6
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Coding to interfaces allows for loose coupling as changes can be made to the interface without the actual implementation being affected.
A good example is when working with SOAP webservices as it is advisable to do contract first which ensures that the WSDL (the contract) is
created first followed by the Java classes. IF organizations consume your webservice and changes were to be made to the WSDL after using the contract first method, these
changes will not affect consumers, however; if contract first was done this would break for all current consumers.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!