0

Im currently studying PHP and came across the concept of an interface. I understand that they are used as a templating structure for the program, but in what occasion would they be used?

Oliver Kucharzewski
  • 2,523
  • 4
  • 27
  • 51

1 Answers1

0

On example, you want to use an external API, but you don't want to explicitly use specific implementation in your code.

You can just create an interface, and you rely on it in the entire app. Any possible implementation only has to implement that interface, so you can switch implementations on the go.

It'll be useful in common tasks like logging, user authentication, mailing, etc.

Mateusz Sip
  • 1,280
  • 1
  • 11
  • 11