posted 17 years ago
Hi,
"Code to Interface" means you write your program to an abstract type(a super class or an interface) and not to a concrete implementation.
for example:
when you write:
You are coding to the concrete implementation- ArrayList.
whereas when you write:
you are coding to an abstract type: List interface.
So, in the first piece of code, the object "myList" is highly coupled to a particular concrete implementation(ArrayList) whereas in the second piece of code it is loosely coupled.Moreover, doing so, you can achieve better flexibility. You can use 'myList' object for any concrete implementation of the abstract type- List.
Hope this helps.
Thanks and regards,
Saurabh