[TYPO3-50-general] File name conventions for classes and interfaces
Martin Kutschker
Martin.Kutschker at n0spam-blackbox.net
Mon Dec 11 13:44:02 CET 2006
Robert Lemke schrieb:
> 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?
Not sure.
Say I have a class MyClass which is no interface and implements no
interface. And there is the interface MyAPI, which defines an interface.
So the files are called: MyClass.php and MyAPI.php. Is this a problem for you?
Maybe this was the reason why Java uses the "I" prefix.
Otherwise your idea is good.
So we have TemplateEngineInterface.php or ITemplateEngine.php but STILL
SmartyTemplateEngine (pre-/suffix dropped).
In the case of implementations of more than one interface I would not use
any interface name in the file name.
Masi
More information about the TYPO3-project-5_0-general
mailing list