importance of Interfaces and Abstract Classes in PHP

This question already has an answer here:

  • What is dependency injection? 31 answers

  • Defining both interfaces and abstract classes are design mechanisms that help create solid software architectures. It doesn't have to do with security. They provide the ability create classes that best capture the real-world situation in which the software is trying to achieve.

    Why is it that some methods have to pass objects instantiating Interfaces and Abstract Classes first before adding it to a normal class when you can directly add it to a normal class? Is it for the security of your code?

    These are all architectural choices by the developer of the code and related to Dependency Injection, you can also read a good SO document about Abstract Classes, that covers both Abstract classes and Interfaces and how they interact.

    链接地址: http://www.djcxy.com/p/14416.html

    上一篇: 如何在其他类之间使用PHP类

    下一篇: PHP中接口和抽象类的重要性