diff --git a/Structural/Adapter/Book.php b/Structural/Adapter/Book.php index 83079d6..88ce1ad 100644 --- a/Structural/Adapter/Book.php +++ b/Structural/Adapter/Book.php @@ -2,25 +2,11 @@ namespace DesignPatterns\Structural\Adapter; -class Book implements BookInterface +interface Book { - /** - * @var int - */ - private $page; + public function turnPage(); - public function open() - { - $this->page = 1; - } + public function open(); - public function turnPage() - { - $this->page++; - } - - public function getPage(): int - { - return $this->page; - } + public function getPage(): int; } diff --git a/Structural/Adapter/BookInterface.php b/Structural/Adapter/BookInterface.php deleted file mode 100644 index d79ee1b..0000000 --- a/Structural/Adapter/BookInterface.php +++ /dev/null @@ -1,12 +0,0 @@ -eBook = $eBook; } @@ -35,7 +35,7 @@ class EBookAdapter implements BookInterface } /** - * notice the adapted behavior here: EBookInterface::getPage() will return two integers, but BookInterface + * notice the adapted behavior here: EBook::getPage() will return two integers, but Book * supports only a current page getter, so we adapt the behavior here * * @return int diff --git a/Structural/Adapter/Kindle.php b/Structural/Adapter/Kindle.php index 03354a6..e261906 100644 --- a/Structural/Adapter/Kindle.php +++ b/Structural/Adapter/Kindle.php @@ -6,7 +6,7 @@ namespace DesignPatterns\Structural\Adapter; * this is the adapted class. In production code, this could be a class from another package, some vendor code. * Notice that it uses another naming scheme and the implementation does something similar but in another way */ -class Kindle implements EBookInterface +class Kindle implements EBook { /** * @var int diff --git a/Structural/Adapter/PaperBook.php b/Structural/Adapter/PaperBook.php new file mode 100644 index 0000000..c988f39 --- /dev/null +++ b/Structural/Adapter/PaperBook.php @@ -0,0 +1,26 @@ +page = 1; + } + + public function turnPage() + { + $this->page++; + } + + public function getPage(): int + { + return $this->page; + } +} diff --git a/Structural/Adapter/README.rst b/Structural/Adapter/README.rst index 6d1c7e0..5b061e4 100644 --- a/Structural/Adapter/README.rst +++ b/Structural/Adapter/README.rst @@ -28,27 +28,27 @@ Code You can also find this code on `GitHub`_ -BookInterface.php - -.. literalinclude:: BookInterface.php - :language: php - :linenos: - Book.php .. literalinclude:: Book.php :language: php :linenos: -EBookAdapter.php +PaperBook.php -.. literalinclude:: EBookAdapter.php +.. literalinclude:: PaperBook.php :language: php :linenos: -EBookInterface.php +EBook.php -.. literalinclude:: EBookInterface.php +.. literalinclude:: EBook.php + :language: php + :linenos: + +EBookAdapter.php + +.. literalinclude:: EBookAdapter.php :language: php :linenos: diff --git a/Structural/Adapter/Tests/AdapterTest.php b/Structural/Adapter/Tests/AdapterTest.php index 3b8c076..6e5de56 100644 --- a/Structural/Adapter/Tests/AdapterTest.php +++ b/Structural/Adapter/Tests/AdapterTest.php @@ -2,7 +2,7 @@ namespace DesignPatterns\Structural\Adapter\Tests; -use DesignPatterns\Structural\Adapter\Book; +use DesignPatterns\Structural\Adapter\PaperBook; use DesignPatterns\Structural\Adapter\EBookAdapter; use DesignPatterns\Structural\Adapter\Kindle; use PHPUnit\Framework\TestCase; @@ -11,7 +11,7 @@ class AdapterTest extends TestCase { public function testCanTurnPageOnBook() { - $book = new Book(); + $book = new PaperBook(); $book->open(); $book->turnPage(); diff --git a/Structural/Adapter/uml/uml.png b/Structural/Adapter/uml/uml.png index 2d7db9f..792ac0d 100644 Binary files a/Structural/Adapter/uml/uml.png and b/Structural/Adapter/uml/uml.png differ