Re: simple interface standard?

From: Date: Mon, 30 Aug 2004 07:09:44 +0000
Subject: Re: simple interface standard?
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-33046@lists.php.net to get a copy of this message
Greg Beaver wrote:
Hi, Would there be an objection to specfying a simple standard for interfaces? <<BEGIN STANDARD>> Mypackage.php Mypackage/Interface.php would be a sample structure, so PEAR.php PEAR/Interface.php would contain the PEAR interfaces. Interface names would follow the convention that already exists: interface Mypackage_InterfaceSomething { } or, interface PEAR_InterfaceSomething { } <<END STANDARD>> This way, I could solve all of my concerns about PEAR_Exception with an interface like so: interface PEAR_InterfaceMultiError extends SPL_Iterator {
    public function errorCount();
    public function addError(PEAR_Exception $e);
    public function addWarning(...);
    public function iterator functions that allow foreach/while
} and then users can do this: if ($e instanceof PEAR_InterfaceMultiError) {
    foreach ($e as $error) {
        // do stuff
    }
} and then count on a consistent API, regardless of how it is actually implemented in extended exception classes. Greg
There were previous discussions around interfaces and PEAR. One of the latest http://marc.theaimsgroup.com/?l=pear-dev&m=109044548904170&w=2 Also see the comments on Util_Observable proposed package. IMHO, having an interface under a specific package doesn't necessarily make sense as the interface is to be "shared" between packages. If you need to implement an interface you don't necessary want to get the whole package. As for the name, the full "Interace" name is preferable to the "I" abbreviation. For several reasons: - if jammed with the name of the interface it's not easy to spot. - Making it stand as _I_ somewhere in the name is not really clear as well. Not everybody is used to that abbreviation. Whereas "_E_" for the exception class is very well suited as every PHP programmer know about the somewhat related error reporting level constants E_*. - Implementing an interface is not that frequent relatively to the size of a application. Same that above, whereas frequency justifies abbreviation for Exception, I don't see it happening for inerfaces... -Philippe

« previous php.pear.dev (#33046) next »