Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f1dbabc

Browse files
committed
Proxy
1 parent 69b594c commit f1dbabc

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

‎Proxy/index.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
/**
4+
* Design pattern "Proxy" (Structural)
5+
* This is demo code
6+
* See for details: http://maxsite.org/page/php-patterns
7+
*/
8+
9+
/**
10+
* Real Class
11+
*/
12+
class RealClass
13+
{
14+
public function operation1()
15+
{
16+
echo 'RealClass operation 1 <br>';
17+
}
18+
19+
public function operation2()
20+
{
21+
echo 'RealClass operation 2 <br>';
22+
}
23+
}
24+
25+
/**
26+
* Proxy for Real Class
27+
*/
28+
class ProxyClass
29+
{
30+
protected $class;
31+
32+
public function __construct()
33+
{
34+
$this->class = new RealClass();
35+
}
36+
37+
/**
38+
* execute RealClass operation1
39+
*/
40+
public function run1()
41+
{
42+
$this->class->operation1();
43+
}
44+
45+
/**
46+
* execute RealClass operation2
47+
*/
48+
public function run2()
49+
{
50+
$this->class->operation2();
51+
}
52+
}
53+
54+
55+
/**
56+
* demo
57+
*/
58+
59+
/**
60+
* create Decorator for Real Class
61+
*/
62+
$p = new ProxyClass();
63+
64+
$p->run1();
65+
$p->run2();
66+
/*
67+
RealClass operation 1
68+
RealClass operation 2
69+
*/
70+
71+
72+
# end of file

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ See details on http://maxsite.org/page/php-patterns
1818
* "Bridge" (Structural)
1919
* "Decorator" (Structural)
2020
* "Flyweight" (Structural)
21+
* "Proxy" (Structural)
2122

2223

2324
(c) MaxSite.org, 2019, http://maxsite.org/

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /