2015-08-13 23:54:40 +02:00
---
layout: pattern
title: Proxy
folder: proxy
2015-08-15 18:03:05 +02:00
permalink: /patterns/proxy/
2016-08-30 15:10:34 +02:00
pumlid: 9SR13OCm30NGLM00udktCS62eCI9x6yesrEfx_Jcehd69c5rEe3X7oBZE-q5HwpXOhahH95oRrHgt0msEldYPHClkow30J5rQko_qB3-VKYG_qjXBOrezGK0
2015-08-20 21:40:07 +02:00
categories: Structural
2015-09-22 18:25:56 +05:30
tags:
- Java
- Gang Of Four
2015-12-28 15:52:44 +02:00
- Difficulty-Beginner
2015-08-13 23:54:40 +02:00
---
2016-01-03 21:14:30 +01:00
## Also known as
Surrogate
2015-11-04 21:13:32 +02:00
2016-01-03 21:14:30 +01:00
## Intent
Provide a surrogate or placeholder for another object to control
2015-08-13 23:54:40 +02:00
access to it.
2016-11-23 22:03:26 +02:00

2015-08-13 23:54:40 +02:00
2016-01-03 21:14:30 +01:00
## Applicability
Proxy is applicable whenever there is a need for a more
2015-08-13 23:54:40 +02:00
versatile or sophisticated reference to an object than a simple pointer. Here
are several common situations in which the Proxy pattern is applicable
2016-11-23 22:03:26 +02:00
* Remote proxy provides a local representative for an object in a different address space.
* Virtual proxy creates expensive objects on demand.
* Protection proxy controls access to the original object. Protection proxies are useful when objects should have different access rights.
2015-08-13 23:54:40 +02:00
2016-01-03 21:14:30 +01:00
## Typical Use Case
2015-08-13 23:54:40 +02:00
2016-11-23 22:03:26 +02:00
* Control access to another object
* Lazy initialization
* Implement logging
* Facilitate network connection
* Count references to an object
2015-08-13 23:54:40 +02:00
2016-12-26 20:16:30 +02:00
## Presentations
* [Proxy ](https://github.com/iluwatar/java-design-patterns/tree/master/proxy/etc/presentation.html )
2016-01-03 21:14:30 +01:00
## Real world examples
2015-08-13 23:54:40 +02:00
* [java.lang.reflect.Proxy ](http://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Proxy.html )
2015-08-15 18:03:05 +02:00
* [Apache Commons Proxy ](https://commons.apache.org/proper/commons-proxy/ )
2016-08-31 16:12:13 +05:30
* Mocking frameworks Mockito, Powermock, EasyMock
2015-09-22 18:25:56 +05:30
2016-01-03 21:14:30 +01:00
## Credits
2015-09-22 18:25:56 +05:30
* [Design Patterns: Elements of Reusable Object-Oriented Software ](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612 )