note 79760 deleted from language.oop5.interfaces by felipe
| From: | felipe@php.net | Date: | Sat, 15 Dec 2007 15:31:34 +0000 |
| Subject: | note 79760 deleted from language.oop5.interfaces by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133572@lists.php.net to get a copy of this message | ||
Note Submitter: ndasilva at rap dot midco dot net
----
Some interesting less-than-documented behavior.
As shown below, interfaces support inheritance, and implementing multiple interfaces which inherit
from the same "parent" interface will *not* cause method name clashes. Observe:
<?php
// Interface declarations:
interface Ia {
public function Foo();
}
interface Ib extends Ia {
public function FooBar();
}
interface Ic extends Ia {
public function Footurama();
}
// Now let's implement them...
class AB implements Ib, Ic {
public function Foo() { }
public function FooBar() { }
public function Footurama() { }
}
$ab = new AB();
?>
It just becomes a matter of remembering to declare concrete methods for every interface-defined
method, which could get a bit hard to read.
I've already had to use this once in an app in which a User object implemented an IUser
interface and extended a DB_Object class, which in turn implemented an IDB_Object interface (for
decorator purposes), and both IUser and IDB_Object had a Find() method declared. Both were using
the exact same Find() method, so I just put that into another interface, IFindable, and set both
IUser and IDB_Object to extend IFindable. Good times.