mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-03 05:27:29 +02:00
cs Adapter
This commit is contained in:
@@ -1,9 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* DesignPatternPHP
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace DesignPatterns\Adapter;
|
namespace DesignPatterns\Adapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -11,15 +7,19 @@ namespace DesignPatterns\Adapter;
|
|||||||
*/
|
*/
|
||||||
class Book implements PaperBookInterface
|
class Book implements PaperBookInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function open()
|
public function open()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function turnPage()
|
public function turnPage()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@@ -7,7 +7,6 @@ namespace DesignPatterns\Adapter;
|
|||||||
*/
|
*/
|
||||||
interface EBookInterface
|
interface EBookInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
function pressNext();
|
function pressNext();
|
||||||
|
|
||||||
function pressStart();
|
function pressStart();
|
||||||
|
@@ -1,27 +1,25 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* DesignPatternPHP
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace DesignPatterns\Adapter;
|
namespace DesignPatterns\Adapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kindle is a concrete electronic book
|
* Kindle is a concrete electronic book
|
||||||
*
|
|
||||||
* @author flo
|
|
||||||
*/
|
*/
|
||||||
class Kindle implements ElecBookInterface
|
class Kindle implements EBookInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function pressNext()
|
public function pressNext()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function pressStart()
|
public function pressStart()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@@ -1,9 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
|
||||||
* DesignPatternPHP
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace DesignPatterns\Adapter;
|
namespace DesignPatterns\Adapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -11,8 +7,17 @@ namespace DesignPatterns\Adapter;
|
|||||||
*/
|
*/
|
||||||
interface PaperBookInterface
|
interface PaperBookInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* method to turn pages
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function turnPage();
|
||||||
|
|
||||||
function turnPage();
|
/**
|
||||||
|
* method to open the book
|
||||||
function open();
|
*
|
||||||
}
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function open();
|
||||||
|
}
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
namespace DesignPatterns\Tests\Adapter;
|
namespace DesignPatterns\Tests\Adapter;
|
||||||
|
|
||||||
use DesignPatterns\Adapter\ElecBookAdapter;
|
use DesignPatterns\Adapter\EBookAdapter;
|
||||||
use DesignPatterns\Adapter\Kindle;
|
use DesignPatterns\Adapter\Kindle;
|
||||||
use DesignPatterns\Adapter\PaperBookInterface;
|
use DesignPatterns\Adapter\PaperBookInterface;
|
||||||
use DesignPatterns\Adapter\Book;
|
use DesignPatterns\Adapter\Book;
|
||||||
@@ -23,13 +23,13 @@ class AdapterTest extends \PHPUnit_Framework_TestCase
|
|||||||
return array(
|
return array(
|
||||||
array(new Book()),
|
array(new Book()),
|
||||||
// we build a "wrapped" electronic book in the adapter
|
// we build a "wrapped" electronic book in the adapter
|
||||||
array(new ElecBookAdapter(new Kindle()))
|
array(new EBookAdapter(new Kindle()))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This client only knows paper book but surprise, surprise, the second book
|
* This client only knows paper book but surprise, surprise, the second book
|
||||||
* is in fact an electronic book.
|
* is in fact an electronic book, but both work the same way
|
||||||
*
|
*
|
||||||
* @dataProvider getBook
|
* @dataProvider getBook
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user