抽象类是否应该始终以 Abstract
为前缀并以 Interface
为后缀(当它是接口(interface)时)?是否有任何标准的命名约定,类似于文件夹结构/命名空间的 PSR-0,但对于类?
这似乎是多余的,因为该语言有专门用于此目的的文字关键字。
abstract class AbstractFoo {}
interface InterfaceFoo {}
trait TraitFoo {}
最佳答案
PHP-FIG 项目确实通过 PSR 命名约定“ByLaw”建议了命名约定 https://www.php-fig.org/bylaws/psr-naming-conventions/
它指出:
接口(interface)必须以 Interface 为后缀:例如
Psr\Foo\BarInterface
抽象类必须以抽象为前缀:例如
Psr\Foo\AbstractBar
特征必须以特征为后缀:例如
Psr\Foo\BarTrait
这些约定通常在包中遵循
关于PHP 关于抽象类和接口(interface)的命名约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13564046/