装饰器模式

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

<?php

abstract class Request {

abstract function handel();

}

class LogRequest extends Request {

function handel() {
echo "LogRequest\n";
}
}

abstract class RequestDecorator extends Request {

protected $request;

public function __construct(Request $request) {
$this->request = $request;
}
}


class AuthRequestDecorator extends RequestDecorator {

function handel() {
echo "AuthRequestDecorator\n";
$this->request->handel();
}

}


class FormRequestDecorator extends RequestDecorator {

function handel() {
echo "FormRequestDecorator\n";
$this->request->handel();
}

}


$AuthRequestDecorator = new FormRequestDecorator(new AuthRequestDecorator(new LogRequest()));
$AuthRequestDecorator->handel();
状态模式 组合模式
You need to set install_url to use ShareThis. Please set it in _config.yml.

评论

You forgot to set the shortname for Disqus. Please set it in _config.yml.
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×