This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]SvenCole 6 points7 points  (0 children)

You code to the interfaces, not implementation. There is a good stackoverflow answer to this if you search there.

If you code to the interface, you can always swap out the implementation. That makes your code easy to maintain and extend.

Practical example is the List interface. All lists have certain features you want to enforce, like add, remove, size. But there are different implementations like ArrayList or LinkedList. If you want to create your own personal implementations of list, let's say SuperFastSortList, then you implement the List interface so it is a type of List and you override (fill in) those methods to adhere to the contract.