Alex Rivera | Logout

Coding to interfaces?

Asked 2009-12-28T18:21:19.187
18

I want to solidify my understanding of the "coding to interface" concept. As I understand it, one creates interfaces to delineate expected functionality, and then implements these "contracts" in concrete classes. To use the interface one can simply call the methods on an instance of the concrete class.

The obvious benefit is knowing of the functionality provided by the concrete class, irrespective of its specific implementation.

Based on the above:

  1. Are there any fallacies in my understanding of "coding to interfaces"?
  2. Are there any benefits of coding to interfaces that I missed?

Thanks.

Edit
Report

1 Answer

5

The main advantage is that the use of an interface loosely couples a class with it's dependencies. You can then change a class, or implement a new concrete interface implementation without ever having to change the classes which depend on it.

answered 2009-12-28T18:30:33.303

Your Answer