forked from cbergau/PHPDesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadapter.php
49 lines (41 loc) · 780 Bytes
/
adapter.php
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
<?php
/**
* Object adapter example
*
* @author Christian Bergau <[email protected]>
* @copyright Free for all
* @link http://en.wikipedia.org/wiki/Adapter_pattern
*/
class Adaptee
{
public function methodB()
{
echo 'MethodB called';
}
}
class Adaptor
{
protected $adaptee;
public function __construct(Adaptee $adaptee)
{
$this->adaptee = $adaptee;
}
public function methodA()
{
$this->adaptee->methodB();
}
}
class Client
{
protected $adaptor;
public function __construct(Adaptor $adaptor)
{
$this->adaptor = $adaptor;
}
public function doWork()
{
$this->adaptor->methodA();
}
}
$client = new Client(new Adaptor(new Adaptee()));
$client->doWork();