Skip to content

Commit 2ff0a00

Browse files
committed
Add class diagram
1 parent 68dac63 commit 2ff0a00

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ One of the most useful and versatile design patterns is the classic Proxy.
1414

1515
Basically it wraps an object and acts as a proxy between the calls to the object. At first thought it might not sound so useful but this simple concept is a great solution to many problems.
1616

17+
![Proxy class diagram]({{ site.baseurl }}/assets/proxy.png)
18+
1719
## Types of proxies
1820

1921
Protection proxy limits access to the object. Protection proxies can also be used to implement more fine grained access control.
@@ -30,8 +32,6 @@ Smart proxies are used to implement reference counting and log calls to the obje
3032

3133
To elaborate how Proxy design pattern works in practise 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 the tower simultaneously. He cast a protection spell on the tower that allows only the three first wizards to enter.
3234

33-
![Proxy class diagram]({{ site.baseurl }}/assets/proxy-class-diagram.png)
34-
3535
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 enhanced `IvoryTower` is called `WizardTowerProxy`. It implements `WizardTower` and wraps `IvoryTower`. Now everyone wanting to access `IvoryTower` needs to go through the `WizardTowerProxy`.
3636

3737
<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>

assets/proxy.png

24.4 KB
Loading

assets/proxy.xml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<mxfile userAgent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36" version="6.0.2.5" editor="www.draw.io" type="device"><diagram name="Page-1">7Vhtb5swEP41kbYPnQJuaPexeVv3YVK1aur60YEL8WowM05K+utnYxswkC6p2rSbmkoNfnx3vpfnLsAATZLiC8fZ6huLgA78YVQM0HTg+x4KPPmlkK1GziwQcxIZoRq4Jg9gwKFB1ySC3BEUjFFBMhcMWZpCKBwMc87uXbElo+6pGY6hA1yHmHbRGxKJlUbPR8MavwQSr+zJ3tDsLHB4F3O2Ts15Ax8ty4/eTrC1ZeTzFY7YfQNCswGacMaEvkqKCVCVW5s2rTffsVv5zSEV+yica4UNpmuwHgdUqo4z5Z3YmowEv9fKpXGCeUzSAbqQu8OskP8lWAam8BPBMr132tgTUIgTTEls9ELpG/DapryKzXd5MmkAOJEGx7S7+qpsLHEIFeyqOBZl/KR9yoJ3EAtcrxe/FKtq7UVbVmJZG1txlTLLZRudtzvQJ6WYwlI0crzLdje8PpdfxgMlW9b4ww15wDz6qKU3TLJuT/d8xzF/A1wQ2Z4XmkXTkmdjw6mpdmjMpNSSlt20JJLlaLxkqTDDxfPNeo4TQtVYugS6AWVVlU4kVAkpGak6YZTx8mTbvWicC87uoLEzLD+KahxHRMbb2Juezrz5qIpEuQ/Fzhb1qsaXAxVYAoJvpYhR8M/NrDCz1A6h+3owVeNk5Q4lMxDNMIwr0/VAkBdmJvTPB+vumxoQVTd+B0yP1awR2fQGbFOuHPcf68g8w+lBPSLddnUquPTl9VvlhYmPfJf4fcz3TnuYHzwH8f23TPwrzortO+X/O8oHnkv5s9ERGY/eIuN336VNqCrE/k3wj99SzAL19zw0G70iy7pPHLNCQBrlnQpJ8EI9y8nVgrLwTsYuIZv8QC/nZVmmQzfjMg98+1Phn0Z2eWv3CiIaW3J1awxoDyDqPBu28iq9ZGsegnuLJCTtQTQeq7rpbybYJpMDxYJs3CP7MmzMX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