From the course: Advanced Design Patterns: Design Principles

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Program to interfaces

Program to interfaces

- [Instructor] Program to Interfaces, Not Implementations. This is a design principle that guides us to make use of abstract types, not concrete ones to allow our designs to be more flexible and maintainable. Program to an interface really means program to a super type. If you're, say, a Java programmer, don't assume we're talking about the interface construct, but instead think more generally. We're really talking about, again, the concept of a super type, whether that be an abstract class or a Java interface or some similar language construct. The point is to be able to exploit polymorphism by programming to a super type so that your actual runtime object isn't locked into your code. To understand this better, let's look at an example. Let's say your have a killer web system that you're developing and it depends on a commercial database. Here we have a killer web system class and it has a property, DB, meant to be set…

Contents