简体   繁体   English

为什么不总是使用抽象而不是接口?

[英]Why not always use abstract instead of interface?

In PHP why not always use abstract instead of interface? 在PHP中为什么不总是使用抽象而不是接口? I do know the following: 我确实知道以下几点:

Use an interface when you want to force developers working in your system (yourself included) to implement a set number of methods on the classes they'll be building. 当您想强制开发人员(包括您自己)在系统中工作以在他们要构建的类上实现一定数量的方法时,请使用接口。

Use an abstract class when you want to force developers working in your system (yourself included) to implement a set numbers of methods and you want to provide some base methods that will help them develop their child classes. 当您要强制系统中的开发人员(包括您自己)执行一定数量的方法,并且要提供一些基本方法来帮助他们开发子类时,请使用抽象类。

if so why not always use abstract (when you want the functionality of an interface) without providing any base methods? 如果是这样,为什么不总是使用抽象(当您需要接口的功能时)而不提供任何基本方法?

因为一个类可以实现多个接口,但是只能扩展一个抽象类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM