Skip to content

Commit 2627aab

Browse files
author
Dominik Liebler
committed
removed Interface-suffix
1 parent e02bcea commit 2627aab

File tree

9 files changed

+48
-48
lines changed

9 files changed

+48
-48
lines changed

Structural/Adapter/Book.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,11 @@
22

33
namespace DesignPatterns\Structural\Adapter;
44

5-
class Book implements BookInterface
5+
interface Book
66
{
7-
/**
8-
* @var int
9-
*/
10-
private $page;
7+
public function turnPage();
118

12-
public function open()
13-
{
14-
$this->page = 1;
15-
}
9+
public function open();
1610

17-
public function turnPage()
18-
{
19-
$this->page++;
20-
}
21-
22-
public function getPage(): int
23-
{
24-
return $this->page;
25-
}
11+
public function getPage(): int;
2612
}

Structural/Adapter/BookInterface.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

Structural/Adapter/EBookInterface.php renamed to Structural/Adapter/EBook.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace DesignPatterns\Structural\Adapter;
44

5-
interface EBookInterface
5+
interface EBook
66
{
77
public function unlock();
88

Structural/Adapter/EBookAdapter.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
namespace DesignPatterns\Structural\Adapter;
44

55
/**
6-
* This is the adapter here. Notice it implements BookInterface,
6+
* This is the adapter here. Notice it implements Book,
77
* therefore you don't have to change the code of the client which is using a Book
88
*/
9-
class EBookAdapter implements BookInterface
9+
class EBookAdapter implements Book
1010
{
1111
/**
12-
* @var EBookInterface
12+
* @var EBook
1313
*/
1414
protected $eBook;
1515

1616
/**
17-
* @param EBookInterface $eBook
17+
* @param EBook $eBook
1818
*/
19-
public function __construct(EBookInterface $eBook)
19+
public function __construct(EBook $eBook)
2020
{
2121
$this->eBook = $eBook;
2222
}
@@ -35,7 +35,7 @@ public function turnPage()
3535
}
3636

3737
/**
38-
* notice the adapted behavior here: EBookInterface::getPage() will return two integers, but BookInterface
38+
* notice the adapted behavior here: EBook::getPage() will return two integers, but Book
3939
* supports only a current page getter, so we adapt the behavior here
4040
*
4141
* @return int

Structural/Adapter/Kindle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* this is the adapted class. In production code, this could be a class from another package, some vendor code.
77
* Notice that it uses another naming scheme and the implementation does something similar but in another way
88
*/
9-
class Kindle implements EBookInterface
9+
class Kindle implements EBook
1010
{
1111
/**
1212
* @var int

Structural/Adapter/PaperBook.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace DesignPatterns\Structural\Adapter;
4+
5+
class PaperBook implements Book
6+
{
7+
/**
8+
* @var int
9+
*/
10+
private $page;
11+
12+
public function open()
13+
{
14+
$this->page = 1;
15+
}
16+
17+
public function turnPage()
18+
{
19+
$this->page++;
20+
}
21+
22+
public function getPage(): int
23+
{
24+
return $this->page;
25+
}
26+
}

Structural/Adapter/README.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,27 @@ Code
2828

2929
You can also find this code on `GitHub`_
3030

31-
BookInterface.php
31+
Book.php
3232

33-
.. literalinclude:: BookInterface.php
33+
.. literalinclude:: Book.php
3434
:language: php
3535
:linenos:
3636

37-
Book.php
37+
PaperBook.php
3838

39-
.. literalinclude:: Book.php
39+
.. literalinclude:: PaperBook.php
4040
:language: php
4141
:linenos:
4242

43-
EBookAdapter.php
43+
EBook.php
4444

45-
.. literalinclude:: EBookAdapter.php
45+
.. literalinclude:: EBook.php
4646
:language: php
4747
:linenos:
4848

49-
EBookInterface.php
49+
EBookAdapter.php
5050

51-
.. literalinclude:: EBookInterface.php
51+
.. literalinclude:: EBookAdapter.php
5252
:language: php
5353
:linenos:
5454

Structural/Adapter/Tests/AdapterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace DesignPatterns\Structural\Adapter\Tests;
44

5-
use DesignPatterns\Structural\Adapter\Book;
5+
use DesignPatterns\Structural\Adapter\PaperBook;
66
use DesignPatterns\Structural\Adapter\EBookAdapter;
77
use DesignPatterns\Structural\Adapter\Kindle;
88
use PHPUnit\Framework\TestCase;
@@ -11,7 +11,7 @@ class AdapterTest extends TestCase
1111
{
1212
public function testCanTurnPageOnBook()
1313
{
14-
$book = new Book();
14+
$book = new PaperBook();
1515
$book->open();
1616
$book->turnPage();
1717

Structural/Adapter/uml/uml.png

-23.2 KB
Loading

0 commit comments

Comments
 (0)