Re: PEAR and interfaces
| From: | David Coallier | Date: | Fri, 05 Jan 2007 00:12:21 +0000 |
| Subject: | Re: PEAR and interfaces | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-45428@lists.php.net to get a copy of this message | ||
On 1/4/07, Gregory Beaver <greg@chiaraquartet.net> wrote:
David Coallier wrote: Hey all, sorry if this is repeatitive, and if it is please point me to the good documentation but I was wondering if it was ever discussed before. The use of interface and it's structure in pear. Currently what I have done is something like this (package: Path_MainPackage) Path_MainPackage: Interface: -------------------- interface Path_MainPackage_Interface { } -------------------- MainPackage class: ----------------------- require_once 'Path/MainPackage/interface/MainPackageInterface.php'; class Path_MainPackage implements Path_MainPackage_Interface { } ----------------------- Let me know if this is the good structure used for PEAR or what shoudl be used if it is not. Hi, There has been a great deal of debate on how best to do this. I think that it may be better to require an I prefix. Why? "Interface" can mean more than just the language construct (think of user interface, etc.). This means there is actually some unintended ambiguity here. It is a recognized practice in other languages to simply prepend I, so that we get: Path/MainPackage/IWhatItDoes.phpOk well if i'm not mistaking that's what I just did, but I have put the interface in an interface directory. As such as this Path/MainPackage/interfaces/MainPackageInterface.php so MainPackage is only using the interface from the package's directory and at least we know that what is in the folder interfaces is an interface related to the package only. Although what I could see is something along the lines of a general directory for all the interfaces in pear. A centralized interfaces directory maybe. In the package.xml file we could mention something like <file role="interface" ..../> and it would go to the interfaces folder thus calling it would automatically be like <?php require_once 'interfaces/NewPackageInterface.php'; class New_Package implements New_Package_Interface { } ?> Of course there could be problems as such as file replicated, etc (namespace problems) and myabe that implementing a new standard as such as all interfaces must be preceded by a prefix could be a solution but again, this is going to be a rowdy discussion as some people like the prefixes and some others dont.
as in PEAR2/IRegistry.php (PEAR2_IRegistry interface) or PhpDocumentor2/Converter/IOutput.php (PhpDocumentor2_Converter_IOutput interface) Both of the examples are hypothetical, btw. I was not in favor of this until I started implementing a few interfaces, and I have become convinced after using them that this is far clearer for code organization. Any discussion is welcome, of course. Greg-- David Coallier, Founder & Software Architect, Agora Production (http://agoraproduction.com) 51.42.06.70.18