简体   繁体   中英

Naming Conventions or Directory Strucure

I'm PHP programmer, but what I want to discuss is influenced by 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.

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 ?

The question is, in Java's Naming Conventions, there is no prefix nor suffix for Interfaces, such as ListsInterface or InterfaceLists .

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.

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. List does. 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).

I think you should check PHP naming conventions instead of Java.

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

Zend provides a good one, nearly considering all the cases.

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

In your case just to show that an interface is an interface, Zend forces you to put a suffix on your interafces. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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