SlideShare uma empresa Scribd logo
1 de 18
PROXY DESIGN PATTERN
by Zafer GENÇ
Why Proxy Patern ?
• Let’s say , there is some system that is very complicated and we’ll make it
simple,
• And, lets say , we are only interested in some necessary parts , objects vs
not all of them
• And , lets say , every time , instantiating and initializing all objects needs a
lot of time , another words , costs a lot.
WHO DOWE CALL ?
Answer is PROXY
Provide a surrogate or placeholder for another object to control access to it.
Where exactly is the Proxy Pattern used ?
This pattern is recommended when either of the following scenarios occur in
your application:
• The object being represented is external to the system.
• Objects need to be created on demand.
• Access control for the original object is required
• Added functionality is required when an object is accessed.
Typically, you'll want to use a proxy when communication with a third party
is an expensive operation, perhaps over a network.The proxy would allow
you to hold your data until you are ready to commit, and can limit the
amount of times that the communication is called.
The proxy is also useful if you want to decouple actual implementation code
from the access to a particular library.
Proxy is also useful for access to large files, or graphics. By using a proxy,
you can delay loading the resource until you really need the data inside.
Without the concept of proxies, an application could be slow, and appear
non-responsive.
What is like ,the structure of this pattern ?
Proxy
Maintains a reference that lets the proxy access the real subject.
Provides an interface identical to subject's so that a proxy can by substituted
for the real subject.
Controls access to the real subject and may be responsible for creating and
deleting it.
Subject
Defines the common interface for Real Subject and Proxy so that a Proxy can
be used anywhere a Real Subject is expected.
Real Subject
Defines the real object that the proxy represents.
Structure – Object Diagram
Applicable Situations
• Virtual Proxy :
Imagine a situation where there is multiple database call to extract huge size
image. Since this is an expensive operation we can possibly use the proxy pattern
which would create multiple proxies and point to the huge size memory
consuming object for further processing.The real object gets created only when a
client first requests/accesses the object and after that we can just refer to the
proxy to reuse the object.This avoids duplication of the object and hence saving
memory.
• Remote Proxy :
The remote proxy provides a local representation of the object which is
present in the different address location.An example can be providing
interface for remote resources such as web services.
• Protective Proxy :
The protective proxy acts as an authorisation layer to verify if the actual
user has access to appropriate content. An example can be thought about the
proxy server which provides restrictive internet access in office. Only the
websites and contents which are valid will be allowed and the remaining ones
will be blocked.
• Smart reference
A smart reference is a replacement for a bare pointer that performs additional actions when an
object is accessed.
Typical uses include
counting the number of references to the real object so that it can be freed automatically when
there are no more references (also called smart pointers)
loading a persistent object into memory when it's first referenced.
checking that the real object is locked before it's accessed to ensure that no other object can
change it.
Examples …
Virtual Proxy Example
• As mentioned earlier virtual proxy is useful to save expensive memory
resources. Let’s take a scenario where the real image contains a huge size
data which clients needs to access.To save our resources and memory the
implementation will be as below:
• We are going to create an Image interface and concrete classes
implementing the Image interface.
• ProxyImage is a a proxy class to reduce memory footprint of
RealImage object loading.
• ProxyPatternDemo, our demo class, will use ProxyImage to get
an Image object to load and display as it needs.
Protection Proxy Example
• Let’s assume that companyABC starts a new policy that employees will now
be prohibited internet access based on their roles. All external emails
websites will be blocked. ( this is shown as an output like «user have internet
access» or «user dont have internet access» according to the rollNumber) . In
such situation we create InternetAccess interface which consists of
operation grantInternetAccess().
• The RealInternetAccess class which allows of internet access for all.
However to restrict this access we will use ProxyInternetAccess class which
will check user’s role and grant access based on their roles.
Proxy Design Patterns
Proxy Design Patterns

Mais conteúdo relacionado

Mais procurados

Cloud architecture
Cloud architectureCloud architecture
Cloud architecture
Adeel Javaid
 

Mais procurados (20)

Adapter pattern
Adapter patternAdapter pattern
Adapter pattern
 
Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
 
Iterator Design Pattern
Iterator Design PatternIterator Design Pattern
Iterator Design Pattern
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Observer Software Design Pattern
Observer Software Design Pattern Observer Software Design Pattern
Observer Software Design Pattern
 
Facade pattern
Facade patternFacade pattern
Facade pattern
 
Decorator design pattern
Decorator design patternDecorator design pattern
Decorator design pattern
 
Bridge pattern
Bridge patternBridge pattern
Bridge pattern
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
State
StateState
State
 
Design Pattern - Chain of Responsibility
Design Pattern - Chain of ResponsibilityDesign Pattern - Chain of Responsibility
Design Pattern - Chain of Responsibility
 
Design pattern-presentation
Design pattern-presentationDesign pattern-presentation
Design pattern-presentation
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design Pattern
 
Cloud architecture
Cloud architectureCloud architecture
Cloud architecture
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
 
Chain of responsibility
Chain of responsibilityChain of responsibility
Chain of responsibility
 
Unit iv
Unit ivUnit iv
Unit iv
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 
Decorator Design Pattern
Decorator Design PatternDecorator Design Pattern
Decorator Design Pattern
 
Composite pattern
Composite patternComposite pattern
Composite pattern
 

Destaque

Herramientas e insumos para mantenimiento preventivo
Herramientas e insumos para mantenimiento preventivoHerramientas e insumos para mantenimiento preventivo
Herramientas e insumos para mantenimiento preventivo
angelicacorrea487
 
3 Years 2 Months Exp. in Dot Net Developer
3 Years 2 Months Exp. in Dot Net Developer3 Years 2 Months Exp. in Dot Net Developer
3 Years 2 Months Exp. in Dot Net Developer
Rahul Shinde
 

Destaque (17)

March 2016 Issue
March 2016 IssueMarch 2016 Issue
March 2016 Issue
 
Taller numero 7
Taller  numero 7Taller  numero 7
Taller numero 7
 
fuente de poder
fuente de poderfuente de poder
fuente de poder
 
Dispositivos de interconexion
Dispositivos de interconexionDispositivos de interconexion
Dispositivos de interconexion
 
Herramientas e insumos para mantenimiento preventivo
Herramientas e insumos para mantenimiento preventivoHerramientas e insumos para mantenimiento preventivo
Herramientas e insumos para mantenimiento preventivo
 
Wingnut paper #1
Wingnut paper #1Wingnut paper #1
Wingnut paper #1
 
Semana 01
Semana 01Semana 01
Semana 01
 
Herramientas del sistema
Herramientas del sistemaHerramientas del sistema
Herramientas del sistema
 
Equipos de interconexion 160608004252
Equipos de interconexion 160608004252Equipos de interconexion 160608004252
Equipos de interconexion 160608004252
 
Topologias marcela
Topologias marcelaTopologias marcela
Topologias marcela
 
Técnico En Sistemas
Técnico En SistemasTécnico En Sistemas
Técnico En Sistemas
 
Herramientas del sistema
Herramientas del sistema Herramientas del sistema
Herramientas del sistema
 
Creative Brief
Creative BriefCreative Brief
Creative Brief
 
3 Years 2 Months Exp. in Dot Net Developer
3 Years 2 Months Exp. in Dot Net Developer3 Years 2 Months Exp. in Dot Net Developer
3 Years 2 Months Exp. in Dot Net Developer
 
Basics of microphone
Basics of microphoneBasics of microphone
Basics of microphone
 
Computer Applications - The Information and Communication Technology in the w...
Computer Applications - The Information and Communication Technology in the w...Computer Applications - The Information and Communication Technology in the w...
Computer Applications - The Information and Communication Technology in the w...
 
Tarjeta grafica
Tarjeta graficaTarjeta grafica
Tarjeta grafica
 

Semelhante a Proxy Design Patterns

Gang of four Proxy Design Pattern
 Gang of four Proxy Design Pattern Gang of four Proxy Design Pattern
Gang of four Proxy Design Pattern
Mainak Goswami
 
Adapter Poxy Pattern
Adapter Poxy PatternAdapter Poxy Pattern
Adapter Poxy Pattern
Philip Zhong
 
Tutor-marked assignment TMA 03 Printable page generated Saturd.docx
Tutor-marked assignment TMA 03 Printable page generated Saturd.docxTutor-marked assignment TMA 03 Printable page generated Saturd.docx
Tutor-marked assignment TMA 03 Printable page generated Saturd.docx
juliennehar
 
B04010 01 0917
B04010 01 0917B04010 01 0917
B04010 01 0917
IJMER
 
Multi tenancy - Wining formula for a PaaS
Multi tenancy - Wining formula for a PaaSMulti tenancy - Wining formula for a PaaS
Multi tenancy - Wining formula for a PaaS
WSO2
 

Semelhante a Proxy Design Patterns (20)

Gang of four Proxy Design Pattern
 Gang of four Proxy Design Pattern Gang of four Proxy Design Pattern
Gang of four Proxy Design Pattern
 
Proxy pattern
Proxy patternProxy pattern
Proxy pattern
 
Adapter Poxy Pattern
Adapter Poxy PatternAdapter Poxy Pattern
Adapter Poxy Pattern
 
TechTalk: Advanced Practices for Visual Test Automation
TechTalk: Advanced Practices for Visual Test AutomationTechTalk: Advanced Practices for Visual Test Automation
TechTalk: Advanced Practices for Visual Test Automation
 
Go f designpatterns 130116024923-phpapp02
Go f designpatterns 130116024923-phpapp02Go f designpatterns 130116024923-phpapp02
Go f designpatterns 130116024923-phpapp02
 
Automate Design Patterns
Automate Design PatternsAutomate Design Patterns
Automate Design Patterns
 
Proxy pattern
Proxy patternProxy pattern
Proxy pattern
 
Proxy pattern
Proxy patternProxy pattern
Proxy pattern
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
Design patterns through java
Design patterns through javaDesign patterns through java
Design patterns through java
 
JAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp conceptsJAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp concepts
 
Advanced web application architecture - Talk
Advanced web application architecture - TalkAdvanced web application architecture - Talk
Advanced web application architecture - Talk
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Design_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.pptDesign_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.ppt
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
 
1 croreprojects dotnet ppt
1 croreprojects dotnet ppt1 croreprojects dotnet ppt
1 croreprojects dotnet ppt
 
Tutor-marked assignment TMA 03 Printable page generated Saturd.docx
Tutor-marked assignment TMA 03 Printable page generated Saturd.docxTutor-marked assignment TMA 03 Printable page generated Saturd.docx
Tutor-marked assignment TMA 03 Printable page generated Saturd.docx
 
B04010 01 0917
B04010 01 0917B04010 01 0917
B04010 01 0917
 
Monk objects
Monk objectsMonk objects
Monk objects
 
Multi tenancy - Wining formula for a PaaS
Multi tenancy - Wining formula for a PaaSMulti tenancy - Wining formula for a PaaS
Multi tenancy - Wining formula for a PaaS
 

Último

+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
Health
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 

Último (20)

Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptx
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Air Compressor reciprocating single stage
Air Compressor reciprocating single stageAir Compressor reciprocating single stage
Air Compressor reciprocating single stage
 

Proxy Design Patterns

  • 2. Why Proxy Patern ? • Let’s say , there is some system that is very complicated and we’ll make it simple, • And, lets say , we are only interested in some necessary parts , objects vs not all of them • And , lets say , every time , instantiating and initializing all objects needs a lot of time , another words , costs a lot. WHO DOWE CALL ?
  • 3. Answer is PROXY Provide a surrogate or placeholder for another object to control access to it.
  • 4. Where exactly is the Proxy Pattern used ? This pattern is recommended when either of the following scenarios occur in your application: • The object being represented is external to the system. • Objects need to be created on demand. • Access control for the original object is required • Added functionality is required when an object is accessed.
  • 5. Typically, you'll want to use a proxy when communication with a third party is an expensive operation, perhaps over a network.The proxy would allow you to hold your data until you are ready to commit, and can limit the amount of times that the communication is called. The proxy is also useful if you want to decouple actual implementation code from the access to a particular library. Proxy is also useful for access to large files, or graphics. By using a proxy, you can delay loading the resource until you really need the data inside. Without the concept of proxies, an application could be slow, and appear non-responsive.
  • 6. What is like ,the structure of this pattern ?
  • 7. Proxy Maintains a reference that lets the proxy access the real subject. Provides an interface identical to subject's so that a proxy can by substituted for the real subject. Controls access to the real subject and may be responsible for creating and deleting it.
  • 8. Subject Defines the common interface for Real Subject and Proxy so that a Proxy can be used anywhere a Real Subject is expected. Real Subject Defines the real object that the proxy represents.
  • 10. Applicable Situations • Virtual Proxy : Imagine a situation where there is multiple database call to extract huge size image. Since this is an expensive operation we can possibly use the proxy pattern which would create multiple proxies and point to the huge size memory consuming object for further processing.The real object gets created only when a client first requests/accesses the object and after that we can just refer to the proxy to reuse the object.This avoids duplication of the object and hence saving memory.
  • 11. • Remote Proxy : The remote proxy provides a local representation of the object which is present in the different address location.An example can be providing interface for remote resources such as web services. • Protective Proxy : The protective proxy acts as an authorisation layer to verify if the actual user has access to appropriate content. An example can be thought about the proxy server which provides restrictive internet access in office. Only the websites and contents which are valid will be allowed and the remaining ones will be blocked.
  • 12. • Smart reference A smart reference is a replacement for a bare pointer that performs additional actions when an object is accessed. Typical uses include counting the number of references to the real object so that it can be freed automatically when there are no more references (also called smart pointers) loading a persistent object into memory when it's first referenced. checking that the real object is locked before it's accessed to ensure that no other object can change it.
  • 14. Virtual Proxy Example • As mentioned earlier virtual proxy is useful to save expensive memory resources. Let’s take a scenario where the real image contains a huge size data which clients needs to access.To save our resources and memory the implementation will be as below: • We are going to create an Image interface and concrete classes implementing the Image interface. • ProxyImage is a a proxy class to reduce memory footprint of RealImage object loading. • ProxyPatternDemo, our demo class, will use ProxyImage to get an Image object to load and display as it needs.
  • 15.
  • 16. Protection Proxy Example • Let’s assume that companyABC starts a new policy that employees will now be prohibited internet access based on their roles. All external emails websites will be blocked. ( this is shown as an output like «user have internet access» or «user dont have internet access» according to the rollNumber) . In such situation we create InternetAccess interface which consists of operation grantInternetAccess(). • The RealInternetAccess class which allows of internet access for all. However to restrict this access we will use ProxyInternetAccess class which will check user’s role and grant access based on their roles.