PHP中的接口有什么意义? - What is the point of interfaces in PHP?

10/14 07:07
阅读数 0

问题:

Interfaces allow you to create code which defines the methods of classes that implement it. 接口允许您创建代码,该代码定义实现它的类的方法。 You cannot however add any code to those methods. 但是,您无法向这些方法添加任何代码。

Abstract classes allow you to do the same thing, along with adding code to the method. 抽象类允许您执行相同的操作,同时向方法添加代码。

Now if you can achieve the same goal with abstract classes, why do we even need the concept of interfaces? 现在,如果您可以使用抽象类实现相同的目标,为什么我们甚至需要接口的概念?

I've been told that it has to do with OO theory from C++ to Java, which is what PHP's OO stuff is based on. 我被告知它与OO理论有关,从C ++到Java,这就是PHP的OO基础。 Is the concept useful in Java but not in PHP? 这个概念在Java中有用但在PHP中没有用吗? Is it just a way to keep from having placeholders littered in the abstract class? 它只是一种避免在抽象类中乱丢占位符的方法吗? Am I missing something? 我错过了什么吗?


解决方案:

参考一: https://en.stackoom.com/question/5K3
参考二: https://stackoom.com/question/5K3
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部