2 edited body
source | link
  1. Interfaces is a part of OOP paradigm. So it's very useful in many cases when you trying to make object oriented parts or your system.
  2. So. Why not? ;-)

Examples: You need to cache your data. How? There is a lot of different engines for caching, which one is the best? Who cares if you have abstract layer which have some ICacheDriver interface with a set of methods like key, get, put, clear, etc. Just implement to it what you need in current project and change it when you need another. Or simple usage of toString. You have a set of different showable objects. You just implement Stringable interface (which describes toString method [there is no really interfaces like that in PHP, but for example]) and just interating over all your object with (string)$obj. There is all you need to do instead of switch (true) { case $obj isntanceof A1: "do 1"; break; ... }

Simple. So there is no question "Why?". There is "who"how to use that better?". ;-) Good luck.

  1. Interfaces is a part of OOP paradigm. So it's very useful in many cases when you trying to make object oriented parts or your system.
  2. So. Why not? ;-)

Examples: You need to cache your data. How? There is a lot of different engines for caching, which one is the best? Who cares if you have abstract layer which have some ICacheDriver interface with a set of methods like key, get, put, clear, etc. Just implement to it what you need in current project and change it when you need another. Or simple usage of toString. You have a set of different showable objects. You just implement Stringable interface (which describes toString method [there is no really interfaces like that in PHP, but for example]) and just interating over all your object with (string)$obj. There is all you need to do instead of switch (true) { case $obj isntanceof A1: "do 1"; break; ... }

Simple. So there is no question "Why?". There is "who to use that better?". ;-) Good luck.

  1. Interfaces is a part of OOP paradigm. So it's very useful in many cases when you trying to make object oriented parts or your system.
  2. So. Why not? ;-)

Examples: You need to cache your data. How? There is a lot of different engines for caching, which one is the best? Who cares if you have abstract layer which have some ICacheDriver interface with a set of methods like key, get, put, clear, etc. Just implement to it what you need in current project and change it when you need another. Or simple usage of toString. You have a set of different showable objects. You just implement Stringable interface (which describes toString method [there is no really interfaces like that in PHP, but for example]) and just interating over all your object with (string)$obj. There is all you need to do instead of switch (true) { case $obj isntanceof A1: "do 1"; break; ... }

Simple. So there is no question "Why?". There is "how to use that better?". ;-) Good luck.

1
source | link

  1. Interfaces is a part of OOP paradigm. So it's very useful in many cases when you trying to make object oriented parts or your system.
  2. So. Why not? ;-)

Examples: You need to cache your data. How? There is a lot of different engines for caching, which one is the best? Who cares if you have abstract layer which have some ICacheDriver interface with a set of methods like key, get, put, clear, etc. Just implement to it what you need in current project and change it when you need another. Or simple usage of toString. You have a set of different showable objects. You just implement Stringable interface (which describes toString method [there is no really interfaces like that in PHP, but for example]) and just interating over all your object with (string)$obj. There is all you need to do instead of switch (true) { case $obj isntanceof A1: "do 1"; break; ... }

Simple. So there is no question "Why?". There is "who to use that better?". ;-) Good luck.