-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdt.php
More file actions
57 lines (36 loc) · 786 Bytes
/
Copy pathdt.php
File metadata and controls
57 lines (36 loc) · 786 Bytes
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
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2016/3/1
* Time: 12:36
*/
abstract class Tiger{
public abstract function climb();
}
class XTiger extends Tiger{
public function climb(){
echo '摔下来';
}
}
class MTiger extends Tiger{
public function climb(){
echo '爬树';
}
}
class Cat{
public function climb(){
echo '飞到天上去';
}
}
class Client{
//是否使用Tiger类
public function call(Tiger $animal){
$animal->climb();
}
}
$client = new Client();
$client->call(new XTiger());
$client->call(new MTiger());
$client->call(new Cat());
//这个例子说明 如果限制类型就是java的多态,但是对于php来说可以不用限制类型,多态没有意义