Skip to content

Commit 6f022b2

Browse files
committed
Work on Proxy blog post
1 parent f85840a commit 6f022b2

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

_posts/2016-12-13-controlling-access-with-proxy-pattern.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,20 @@ Basically it wraps an object and acts as a proxy between calls to the object. At
1818

1919
To elaborate let's think of a simple example. In a fantasy land far away inhabited by creatures from hobbits to dragons the mystic profession of wizard also exists. Wizards are known from their great magic but this power comes with a price. To upkeep and gain spell power the wizards must spend their time studying spellbooks and practising their spells. The best place in the neighborhood to study is the famous Ivory Tower built by the archmage Ivorious and it has become very popular among the wizards. However, to keep his tower tidy and not too crowded Ivorious decided to limit the amount of wizards that are allowed to enter simultaneously. He cast a protection spell on the tower that allows only the three first wizards to enter.
2020

21+
![Proxy class diagram]({{ site.baseurl }}/assets/proxy-class-diagram.png)
22+
2123
The class diagram shows the structure used to implement the Proxy pattern. WizardTower is the interface for all the towers and IvoryTower implements it. The plain IvoryTower allows everyone to enter but Ivorius has specifically cast a protection spell on it to limit the number of simultaneous visitors. The protection spell WizardTowerProxy also implements WizardTower but then it wraps IvoryTower. Now everyone wanting to access IvoryTower needs to go through WizardTowerProxy.
2224

25+
<script src="http://gist-it.appspot.com/http://github.com/iluwatar/java-design-patterns/raw/master/proxy/src/main/java/com/iluwatar/proxy/WizardTower.java?slice=27:"></script>
26+
27+
<script src="http://gist-it.appspot.com/http://github.com/iluwatar/java-design-patterns/raw/master/proxy/src/main/java/com/iluwatar/proxy/IvoryTower.java?slice=32:"></script>
28+
29+
<script src="http://gist-it.appspot.com/http://github.com/iluwatar/java-design-patterns/raw/master/proxy/src/main/java/com/iluwatar/proxy/Wizard.java?slice=29:"></script>
30+
31+
<script src="http://gist-it.appspot.com/http://github.com/iluwatar/java-design-patterns/raw/master/proxy/src/main/java/com/iluwatar/proxy/WizardTowerProxy.java?slice=32:"></script>
32+
33+
<script src="http://gist-it.appspot.com/http://github.com/iluwatar/java-design-patterns/raw/master/proxy/src/main/java/com/iluwatar/proxy/App.java?slice=40:"></script>
34+
2335
## Types of proxies
2436

2537
What we have seen in the previous tutorial is an example of protection proxy that limits access to the object. Protection proxies can also be used to implement more fine grained access control.

assets/proxy-class-diagram.png

22.4 KB
Loading

0 commit comments

Comments
 (0)