<?php/*** Created by PhpStorm.* User: insgeek* Date: 2017年2月22日* Time: 12:04* 适配器模式2*/namespace DesignPattern\AdapterPattern;interface BookInterface{public function turnPage();public function open();public function getPage():int ;}class Book implements BookInterface{private $page;public function open(){// TODO: Implement open() method.$this->page = 1;}public function turnPage(){// TODO: Implement turnPage() method.$this->page++;}public function getPage() : int{// TODO: Implement getPage() method.return $this->page;}}class EBookAdapter implements BookInterface{protected $eBook;public function __construct(EBookInterface $EBook){$this->eBook = $EBook;}public function open(){// TODO: Implement open() method.$this->eBook->unlock();}public function turnPage(){// TODO: Implement turnPage() method.$this->eBook->pressNext();}public function getPage() : int{// TODO: Implement getPage() method.return $this->eBook->getPage()[0];}}interface EBookInterface{public function unlock();public function pressNext();public function getPage() :array ;}class Kindle implements EBookInterface{private $page = 1;private $totalPages = 100;public function pressNext(){// TODO: Implement pressNext() method.$this->page++;}public function unlock(){// TODO: Implement unlock() method.}public function getPage(): array{// TODO: Implement getPage() method.return [$this->page, $this->totalPages];}}$kindle = new Kindle();$book = new EBookAdapter($kindle);$book->open();$book->getPage();$book->turnPage();$book->getPage();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。