简体   繁体   English

命名约定或目录结构

[英]Naming Conventions or Directory Strucure

I'm PHP programmer, but what I want to discuss is influenced by Java. 我是PHP程序员,但我想讨论的是Java的影响。

After read some articles about Hungarian Notation and Naming Conventions of several Languages, I proved how clear are the Java's Naming Convention for Interfaces, I have one question. 在阅读了一些关于匈牙利表示法和几种语言命名约定的文章后,我证明了Java的接口命名约定有多清楚,我有一个问题。

Considering the Object Collections' case, where we have an Abstract Class called AbstractCollection and the concrete class called Lists , how should I name an Interface for Lists ? 考虑到对象集合的情况下,我们有一个抽象类, 类AbstractCollection叫和被叫列出具体的类,我应该如何命名对象列出接口

The question is, in Java's Naming Conventions, there is no prefix nor suffix for Interfaces, such as ListsInterface or InterfaceLists . 问题是,在Java的命名约定中,接口没有前缀或后缀,例如ListsInterfaceInterfaceLists

Lists IS an Interface name and, obviously, at least in PHP, two files in same directory cannot have the same name of a class or interface. 列表是一个接口名称,显然,至少在PHP中,同一目录中的两个文件不能具有相同的类或接口名称。

Not EVERY class needs an Interface, I know, but what if I decide to move to a programming team? 我知道,不是每个类都需要一个接口,但如果我决定转到编程团队呢? The other programmers may use my classes, but they should not open the class files to see what public methods it offers. 其他程序员可能会使用我的类,但他们不应该打开类文件来查看它提供的公共方法。

Just by reading its Interface, everything is clear. 只需阅读其界面,一切都很清楚。

The Directory Structure point came from the possibility to add a subdirectory with the same name of the Interface and, inside it, the concrete class' file. 目录结构点来自于添加具有相同名称的接口的子目录的可能性,并在其中添加具体类的文件。 Eg: 例如:

/  
/Collections  
/Collections/Lists.php <-- Interface  
/Colection/Lists/Lists.php <--- Concrete Class  

What now? 现在怎么办?

You shouldn't give an interface and a class the same name. 您不应该为接口和类指定相同的名称。 Never. 决不。 For your readers sake. 为了您的读者的缘故。

I think your particular problem has little to do with convention, but with a concrete naming problem Lists doesn't sound like an interface at all. 我认为你的特殊问题与约定没什么关系,但是具有一个具体的命名问题Lists听起来根本不像一个接口。 List does. List But in that case an implementing class would have a more concrete name, like List_DoublyLinked and List_SinglyLinked (or whatever kind of list you are talking about). 但在这种情况下,实现类将具有更具体的名称,如List_DoublyLinkedList_SinglyLinked (或者您正在讨论的任何类型的列表)。

I think you should check PHP naming conventions instead of Java. 我认为你应该检查PHP命名约定而不是Java。

http://framework.zend.com/manual/en/coding-standard.naming-conventions.html http://framework.zend.com/manual/en/coding-standard.naming-conventions.html

Zend provides a good one, nearly considering all the cases. Zend提供了一个很好的,几乎考虑了所有情况。

Symfony has another ( http://trac.symfony-project.org/wiki/HowToContributeToSymfony#CodingStandards ), Pear has another ( http://pear.php.net/manual/en/standards.php ) too. Symfony有另一个( http://trac.symfony-project.org/wiki/HowToContributeToSymfony#CodingStandards),Pear还有另一个( http://pear.php.net/manual/en/standards.php )。

In your case just to show that an interface is an interface, Zend forces you to put a suffix on your interafces. 在你的情况下,只是为了表明接口是一个接口,Zend强制你在你的接口上添加一个后缀。 So your dir structure should be like: 所以你的目录结构应该是这样的:

Collections/
Collections/ListsInterface.php
Collections/Lists/ListAbstract.php
Collections/Lists/MyList.php

I don't know if this post answers your question but I hope that it helps. 我不知道这篇文章是否回答了你的问题,但我希望它有所帮助。

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

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