note 115451 added to language.oop5.interfaces
| From: | serverdigital at gmail dot com | Date: | Thu, 24 Jul 2014 23:16:27 +0000 |
| Subject: | note 115451 added to language.oop5.interfaces | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200052@lists.php.net to get a copy of this message | ||
Hi guys, let me show a very useful example of interface to use in PHP, can found more information at
http://code.tutsplus.com/tutorials/solid-part-4-the-dependency-inversion-principle--net-36872
class Test extends PHPUnit_Framework_TestCase {
function testItCanReadAPDFBook() {
$b = new PDFBook();
$r = new EBookReader($b);
$this->assertRegExp('/pdf book/', $r->read());
}
function testItCanReadAMobiBook() {
$b = new MobiBook();
$r = new EBookReader($b);
$this->assertRegExp('/mobi book/', $r->read());
}
}
interface EBook {
function read();
}
class EBookReader {
private $book;
function __construct(EBook $book) {
$this->book = $book;
}
function read() {
return $this->book->read();
}
}
class PDFBook implements EBook {
function read() {
return "reading a pdf book.";
}
}
class MobiBook implements EBook {
function read() {
return "reading a mobi book.";
}
}
----
Server IP: 72.52.91.14
Probable Submitter: 146.83.180.141
----
Manual Page -- http://php.net/manual/en/language.oop5.interfaces.php
Edit -- https://master.php.net/note/edit/115451
Del: integrated -- https://master.php.net/note/delete/115451/integrated
Del: useless -- https://master.php.net/note/delete/115451/useless
Del: bad code -- https://master.php.net/note/delete/115451/bad+code
Del: spam -- https://master.php.net/note/delete/115451/spam
Del: non-english -- https://master.php.net/note/delete/115451/non-english
Del: in docs -- https://master.php.net/note/delete/115451/in+docs
Del: other reasons-- https://master.php.net/note/delete/115451
Reject -- https://master.php.net/note/reject/115451
Search -- https://master.php.net/manage/user-notes.php