[TYPO3-50-general] File name conventions for classes and interfaces

Joerg Schoppet joerg at schoppet.de
Wed Dec 6 08:35:46 CET 2006


Robert Lemke wrote:
> Hi folks,
> 
> during the last days I've been thinking again about our naming 
> convention for .php files. Currently they are like this:
> 
>    class.T3C_PackageName_ComponentClassName.php
>    interface.T3C_PackageName_ComponentInterfaceName.php
>    exception.T3C_PackageName_ComponentExceptionName.php
> 
> There are two things I don't like about it:
> 
>   a) Why is an exception so special that it deserves its own name?
>      In my eyes, it's just a class so I wouldn't make an exception
>      here.
> 
>   b) After staring at it for a while I like it better if we use
>      "class" and "interface" as a suffix rather than a prefix
>      because the package- / component name is more important and
>      sorting is nicer / more logic.
> 
> I therefore propose switching to the folloing pattern:
> 
>    T3C_PackageName_ComponentClassName.class.php
>    T3C_PackageName_ComponentInterfaceName.interface.php
> 
> And furthermore, extend the naming convention for classes: If a class 
> implements one interface, it should be named after it:
> 
>    T3C_Hola_HelloWorld.interface.php
>    T3C_Hola_HelloWorldImplementation.interface.php
> 
> What do you think?
> 
Following this discussion, I see, that there are three "file-types" to 
find a naming convention:
- Classes
- Interfaces
- Exceptions

Looking a little bit to other programming languages (e.g. Java), what 
about the following:

- Classes (e.g. HelloWorld) -> HelloWorld.php
- Interfaces (e.g. IHelloWorld) -> IHelloWorld.php
- Exceptions (e.g. HelloWorldException) -> HelloWorldException.php

This only works reasonable, if there is one folder (e.g. src), which 
only holds OO-material. If this is clear, then you don't need special 
identifiers in the filename (e.g. class, interface, exception).
You can simple look at the file name and know what is in and potential 
autoload-functions can "simple" jump in the src-folder, append a ".php" 
and you have it.

Furthermore it is an oo-standard for java since years and is established 
there and proven.

Regards

Joerg Schoppet


More information about the TYPO3-project-5_0-general mailing list