gpt4 book ai didi

php - 命名抽象类

转载 作者:行者123 更新时间:2023-12-01 22:43:59 25 4
gpt4 key购买 nike

您认为通过给抽象类的名称添加前缀或后缀来区分抽象类和非抽象类是一种好习惯吗?在这方面最常见的做法是什么?

以下是我一直在思考的几种“格式”:

  • Foo_Base
  • Foo_Abstract
  • Abstract_Foo
  • Base_Foo

下划线和字母大小写的使用无关紧要。

编辑:Zend Framework 似乎使用了“抽象”后缀 ( source)。

最佳答案

Do you think it's a good practice to differentiate abstract from non-abstract classes by giving their name a prefix or a suffix?

除非您遵循某些约定,否则我建议不要将这种类型的元数据附加到您的类名中。基本上,它将代码与其他地方可用的信息混在一起。对我来说它类似于 hungarian notation这是许多程序员所厌恶的。

Here are a few "formats" I've been thinking about...

如果必须选择,我会选择 AbstractFoo

根据这些PHP Coding Standard你真的应该避免 _:

Class Names

  • Use upper case letters as word separators, lower case for the rest of a word
  • First character in a name is upper case
  • No underbars ('_')

Justification

  • Of all the different naming strategies many people found this one the best compromise.

Example

class NameOneTwo

class Name

关于php - 命名抽象类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6140386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com