Asked • 07/19/19

What does it mean to "program to an interface"?

I have seen this mentioned a few times and I am not clear on what it means. When and why would you do this? I know what interfaces do, but the fact I am not clear on this makes me think I am missing out on using them correctly. Is it just so if you were to do: IInterface classRef = new ObjectWhatever()You could use any class that implements `IInterface`? When would you need to do that? The only thing I can think of is if you have a method and you are unsure of what object will be passed except for it implementing `IInterface`. I cannot think how often you would need to do that. Also, how could you write a method that takes in an object that implements an interface? Is that possible?

1 Expert Answer

By:

Patrick B. answered • 07/19/19

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.