FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Design-patterns/builder.php at master · LaughingMeMe/Design-patterns · GitHub
LaughingMeMe
Design-patterns
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
Design-patterns
/
builder.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
42 lines (34 loc) · 939 Bytes
Breadcrumbs
Design-patterns
/
builder.php
Copy path
File metadata and controls
42 lines (34 loc) · 939 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
<?php
//建造者模式定义了处理其他对象的复杂构建的对象设计
//应用环境:当创建一个对象的构造有一定的复杂性,在某个对象的构造和配置方法改变时候可以尽可能的减少重复更改代码
class
product{
protected
$
_type
=
''
;
protected
$
_size
=
''
;
protected
$
_color
=
''
;
public
function
setType
(
$
type
){
$
this
->
_type
=
$
type
;
}
public
function
setSize
(
$
size
){
$
this
->
_size
=
$
size
;
}
public
function
setColor
(
$
color
){
$
this
->
_color
=
$
color
;
}
}
class
ProductBulider{
protected
$
product
;
protected
$
config
;
public
function
__construct
(
$
config
){
$
this
->
product
=
new
product
();
$
this
->
config
=
$
config
;
}
public
function
build
(){
$
this
->
product
->
setType
(
$
this
->
config
[
'
type
'
]);
$
this
->
product
->
setSize
(
$
this
->
config
[
'
size
'
]);
$
this
->
product
->
setColor
(
$
this
->
config
[
'
color
'
]);
}
public
function
getInstance
(){
return
$
this
->
product
;
}
}
?>
Back
|
FazBrowse Home
|
New Git URL