-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadapter.php
More file actions
72 lines (57 loc) · 1.21 KB
/
adapter.php
File metadata and controls
72 lines (57 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
</head>
<body>
<?php
/**
* Imagine que nao pode alterar a classe simplebook.
* Mais a aplicação final precisa usar o método getAuthorAndTitle
*
* Então é criado um BookAdapter para conter o metodo necessário.
*/
class SimpleBook
{
private $author;
private $title;
function __construct($author_in, $title_in)
{
$this->author = $author_in;
$this->title = $title_in;
}
function getAuthor()
{
return $this->author;
}
function getTitle()
{
return $this->title;
}
}
class BookAdapter
{
private $book;
function __construct(SimpleBook $book_in)
{
$this->book = $book_in;
}
function getAuthorAndTitle()
{
return $this->book->getTitle() . ' de ' . $this->book->getAuthor();
}
}
// client
writeln('INICIANDO O TESTE:');
writeln('');
$book = new SimpleBook("THE BLACK BOOK", "Adriano Waltrick");
$bookAdapter = new BookAdapter($book);
writeln('Autor de Título: ' . $bookAdapter->getAuthorAndTitle());
writeln('');
writeln('Fim do TEste');
function writeln($line_in)
{
echo $line_in . "<br/>";
}
?>
</body>
</html>