Skip to content

Commit b0b9071

Browse files
committed
Facade
0 parents commit b0b9071

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

Facade/index.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
/**
4+
* Design pattern "Facade" (Structural) or "Delegation" (Fundamental)
5+
* This is demo code
6+
* See for details: http://maxsite.org/page/php-patterns
7+
*/
8+
9+
/**
10+
* Unit 1
11+
*/
12+
class Unit1
13+
{
14+
public function run()
15+
{
16+
echo 'Unit1 run <br>';
17+
}
18+
}
19+
20+
/**
21+
* Unit 2
22+
*/
23+
class Unit2
24+
{
25+
public function show()
26+
{
27+
echo 'Unit2 show <br>';
28+
}
29+
}
30+
31+
/**
32+
* Unit 3
33+
*/
34+
class Unit3
35+
{
36+
public function out()
37+
{
38+
echo 'Unit3 out <br>';
39+
}
40+
}
41+
42+
/**
43+
* Facade start all units
44+
*/
45+
class Facade
46+
{
47+
protected $unit1;
48+
protected $unit2;
49+
protected $unit3;
50+
51+
public function __construct()
52+
{
53+
$this->unit1 = new Unit1();
54+
$this->unit2 = new Unit2();
55+
$this->unit3 = new Unit3();
56+
}
57+
58+
public function start()
59+
{
60+
$this->unit1->run();
61+
$this->unit2->show();
62+
$this->unit3->out();
63+
}
64+
}
65+
66+
/**
67+
* demo
68+
*/
69+
70+
$f = new Facade();
71+
$f->start();
72+
/*
73+
Unit1 run
74+
Unit2 show
75+
Unit3 out
76+
*/
77+
78+
79+
# end of file

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) maxsite.org (http://maxsite.org/)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Software design pattern for PHP
2+
3+
See details on http://maxsite.org/page/php-patterns
4+
5+
* "Facade" (Structural) / "Delegation" (Fundamental)
6+
7+
8+
(c) MaxSite.org, 2019, http://maxsite.org/

0 commit comments

Comments
 (0)