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

Robert Lemke robert at typo3.org
Mon Dec 11 10:17:56 CET 2006


Hi Martin,

Am 11.12.2006 um 09:39 schrieb Martin Kutschker:

> Too verbose but not obvious. I think I'm too dumb to get the  
> difference
> between the definition and the implementation. And how does this  
> differ
> from a class file?
>
> So, going back to the original suggestion I'd use a "Interface"  
> suffix as
> the "I" is really ugly:
>
> HelloWorld.php
> HelloWorldInterface.php
> HelloWorldException.php

That naming has the disadvantage that only one implementation of the  
interface is named after the interface. What I meant was this:

Let's say we have an interface which describes how a "Greeter" class  
should look like, then we call the interface "Greeter". One  
implementation of a greeter could be the "HelloWorldGreeter". An  
alternative implementation would be the "HelloMartinGreeter". Both  
are greeters and therefore implement the "Greeter" interface.

Another example: An interface defines the API for a Template Engine,  
it is therefore called "TemplateEngine". Now we have three  
implementations:

   - SmartyTemplateEngine (implements TemplateEngine)
   - TemplaVoilaTemplateEngine (implements TemplateEngine)
   - ClassicTemplateEngine (implements TemplateEngine)

Someone wants to enhance the ClassicTemplateEngine by adding the  
automaketemplate functionality. He creates a new class which inherits  
the ClassicTemplateEngine and adds or replaces some methods. It is  
called "EnhancedClassicTemplateEngine".

The question you should always be able to ask is: "Is [Class name] a  
[Interface name]?" ("Is SmartyTemplateEngine a TemplateEngine?").
Sometimes you might even want to use interfaces just because you want  
to be able to ask the previous question - the interface doesn't  
neccessarily add any new methods. These interfaces are then called  
"marker interfaces" because the mark your implementation.

You see what I mean?

-- 
robert
http://typo3.org/gimmefive




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