Reasons why you should be coding with interfaces

  • Interfaces enable you to code against pure abstractions, not implementations. Pure abstraction is the best thing for loose code coupling.
  • Interfaces let you make the coupling between classes also very loose, which lets you alter your implementations at runtime more easily, in turn allowing you to create very pluggable implementations for when you think of a better way to do something without having to change your code radically.
  • Interfaces allow for good inter-module communications, especially useful when you have different teams working on different modules - this way, you don’t need to know how the other team’s code works to interface with it.
  • Interfaces make your code more testable because you can readily substitute implementations, even a fake one. This lets you test using, for example, a fake database returning canned data instead of actually having to connect to and use an active, vulnerable database.
  • Interfaces are useful for implementing design patterns such as Model-View-Controller (MVC) and Model-View-ViewModel, and for dependency injection frameworks.

Full post here, 6 mins read