SlideShare uma empresa Scribd logo
1 de 25
Proxy Design pattern
Control the access to your objects
Motivation
 The need to control the access to a certain object
Intent
 The Proxy pattern provides a surrogate or placeholder for another
object to control access to it
 This ability to control the access to an object can be required for a
variety of reasons:
 To hide information about the real object to the client

 To perform optimization like on demand loading
 To do additional house-keeping job like audit tasks
 Proxy design pattern is also known as surrogate design pattern
Context
Sometimes a client object may not be able to access a service provider
object (also referred to as a target object) by normal means. This could
happen for a variety of reasons depending on:

 The location of the target object
 The target object may be present in a different address space in the same or a
different computer.

 The state of existence of the target object
 The target object may not exist until it is actually needed to render a service or
the object may be in a compressed form.

 Special Behavior
 The target object may offer or deny services based on the access privileges of its
client objects. Some service provider objects may need special consideration
when used in a multithreaded environment
Solution
In such cases, the Proxy pattern suggests using a separate object referred to
as a proxy to provide a means for different client objects to access the target
object in a normal, straightforward manner.
 The Proxy object offers the same interface as the target object.
 The Proxy object interacts with the target object on behalf of a client
object and takes care of the specific details of communicating with the
target object
 Client objects need not even know that they are dealing with Proxy for the
original object.

 Proxy object serves as a transparent bridge between the client and an
inaccessible remote object or an object whose instantiation may have
been deferred.
Implementation
 UML class diagram for the Proxy Pattern
Implementation
The participants classes in the proxy pattern are:
 Subject - Interface implemented by the RealSubject and representing its
services. The interface must be implemented by the proxy as well so that
the proxy can be used in any location where the RealSubject can be
used
 Proxy
 Maintains a reference that allows the Proxy to access the RealSubject.
 Implements the same interface implemented by the RealSubject so that the
Proxy can be substituted for the RealSubject.
 Controls access to the RealSubject and may be responsible for its creation and
deletion.
 Other responsibilities depend on the kind of proxy.

 RealSubject - the real object that the proxy represents
Applicability
 Proxies are useful wherever there is a need for a more sophisticated
reference to a object than a simple pointer or simple reference can
provide
 Use the Proxy Pattern to create a representative object that controls
access to another object, which may be remote, expensive to
create or in need of securing
 There are several use-case scenarios that are often repeatable in
practice
Applicability
 Remote Proxy
 The remote proxy provides a local representation of the object which is present
in the different address location

 Virtual Proxy
 delaying the creation and initialization of expensive objects until needed, where
the objects are created on demand

 Protection Proxy
 The protective proxy acts as an authorization layer to verify if the actual user has
access to appropriate content

 Smart Reference
 provides additional actions whenever a subject is referenced, such as counting
the number of references to an object
Applicability
 Firewall Proxy
 controls access to a set of network resources, protecting the subject from “bad”
clients

 Caching Proxy
 Provides temporary storage for results of operations that are expensive. It can
also allow multiple clients to share the results to reduce computation or network
latency

 Synchronization Proxy
 provides safe access to a subject from multiple threads

 Copy-On-Write Proxy
 controls the copying of an object by deferring the copying of an object until it is
required by a client. This is a variant of the Virtual Proxy

 Complexity Hiding Proxy
Example: Remote Proxy
 Solves the problem when the real subject is a remote object. A remote
object is object that exists outside of the current Java Virtual Machine
whether it be in another JVM process on the same machine or a far
machine accessible by network.
 The Remote Proxy pattern enables communication with minimal
modification to existing code
 The Remote Proxy acts as a local representative to the remote object
 The client call methods of the proxy
 The proxy forwards the calls to the remote object
 To the client, it appears as though it is communicating directly with the remote
object
Example: Remote Proxy
Example: Remote Proxy
public interface ISubject {
public String doHeavyTask(String arguments);
}
public class RealSubject implements ISubject{

@Override
public String doHeavyTask(String arguments) {
//do the heavy task..
//generate results
String results = new String("Results");
return results;
}
}
Example: Remote Proxy
public class Proxy implements ISubject{
@Override
public String doHeavyTask(String arguments) {
//start of the stub routine
//pack arguments and generate the request..
//send the request and wait for the response
//unpack results from the response
String results = new String("Results");
//end of the stub routine
return results;
}
}
Example: Remote Proxy
public class Skeleton {
/*
* */
public void receiveRequest(String request){
//unpack the request
//object?
RealSubject subject = new RealSubject();
//method? arguments?
String result = subject.doHeavyTask("arguments");
//pack response with the result
//send the response
}
}
Example: Remote Proxy
Example: Virtual Proxy
 Solves the problems that arises while working directly with objects
that are expensive to create, initialize and maintain in concern with
time or memory consumption
 In this situations the Virtual Proxy:
 acts as a representative for an object that may be expensive to create
 often defers the creation of the object until it is needed
 also acts as a surrogate for the object before and while it is being
created. After that, the proxy delegates requests directly to the
RealSubject
Example: Virtual Proxy
Example: Virtual Proxy
Example: Virtual Proxy
class ImageProxy implements Icon {
ImageIcon imageIcon;
public int getIconWidth() {
if (imageIcon != null) {
return imageIcon.getIconWidth();
} else {
return 800;
}
}
public int getIconHeight() {
if (imageIcon != null) {
return imageIcon.getIconHeight();
} else {
return 600;
}
}
}
Example: Virtual Proxy
public void paintIcon(final Component c, Graphics g, int x, int y) {
if (imageIcon != null) {
imageIcon.paintIcon(c, g, x, y);
} else {
g.drawString("Loading CD cover, please wait...", x+300, y+190);
if (!retrieving) {
retrieving = true;
retrievalThread = new Thread(new Runnable() {
public void run() {
try {
imageIcon = new ImageIcon(imageURL, "CD Cover");
c.repaint();
} catch (Exception e) {}
}
});
retrievalThread.start();
}
}
}
Example: Virtual Proxy
 Refactoring the code:
URL url = new URL("http://images.amazon.com/images/some_image.jpg");
Icon icon = new ImageIcon(url);
Icon icon = new ImageProxy(url);
int iconHeight = icon.getIconHeight();
int iconWidth = icon.getIconWidth();
icon.paintIcon(c, g, x, y);
Related patterns
Many design patterns can have similar or exactly same structure but
they still differ from each other in their intent.
 Adapter design pattern
 Adapter provides a different interface to the object it adapts and
enables the client to use it to interact with it, while proxy provides the
same interface as the subject

 Decorator design pattern
 A decorator implementation can be the same as the proxy however a
decorator adds responsibilities to an object while a proxy controls access
to it
Questions
“

Thank you
for your attention

”

Sashe Klechkovski
December, 2013

Mais conteúdo relacionado

Mais procurados

Presentation on Template Method Design Pattern
Presentation on Template Method Design PatternPresentation on Template Method Design Pattern
Presentation on Template Method Design Pattern
Asif Tayef
 

Mais procurados (20)

Design Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternDesign Pattern - Factory Method Pattern
Design Pattern - Factory Method Pattern
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
 
Adapter pattern
Adapter patternAdapter pattern
Adapter pattern
 
Design Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternDesign Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory Pattern
 
Facade pattern
Facade patternFacade pattern
Facade pattern
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 
OOP and FP
OOP and FPOOP and FP
OOP and FP
 
Iterator
IteratorIterator
Iterator
 
Flyweight pattern
Flyweight patternFlyweight pattern
Flyweight pattern
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern Presentation
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design Pattern
 
Struts
StrutsStruts
Struts
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Presentation on Template Method Design Pattern
Presentation on Template Method Design PatternPresentation on Template Method Design Pattern
Presentation on Template Method Design Pattern
 
Facade Pattern
Facade PatternFacade Pattern
Facade Pattern
 
Creational pattern
Creational patternCreational pattern
Creational pattern
 
Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
 
Composite pattern
Composite patternComposite pattern
Composite pattern
 

Semelhante a Proxy design pattern

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
 
Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805
LearningTech
 
Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805
LearningTech
 
Factory method, strategy pattern & chain of responsibilities
Factory method, strategy pattern & chain of responsibilitiesFactory method, strategy pattern & chain of responsibilities
Factory method, strategy pattern & chain of responsibilities
babak danyal
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWARE
FIWARE
 
WPF - Controls & Data
WPF - Controls & DataWPF - Controls & Data
WPF - Controls & Data
Sharada Gururaj
 

Semelhante a Proxy design pattern (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
 
Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805
 
Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805
 
RMI (Remote Method Invocation)
RMI (Remote Method Invocation)RMI (Remote Method Invocation)
RMI (Remote Method Invocation)
 
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
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
INTRODUCTION TO CLIENT SIDE PROGRAMMING
INTRODUCTION TO CLIENT SIDE PROGRAMMINGINTRODUCTION TO CLIENT SIDE PROGRAMMING
INTRODUCTION TO CLIENT SIDE PROGRAMMING
 
Dependency Injection, Zend Framework and Symfony Container
Dependency Injection, Zend Framework and Symfony ContainerDependency Injection, Zend Framework and Symfony Container
Dependency Injection, Zend Framework and Symfony Container
 
Diving in the Flex Data Binding Waters
Diving in the Flex Data Binding WatersDiving in the Flex Data Binding Waters
Diving in the Flex Data Binding Waters
 
Overview of Microsoft .Net Remoting technology
Overview of Microsoft .Net Remoting technologyOverview of Microsoft .Net Remoting technology
Overview of Microsoft .Net Remoting technology
 
Factory method, strategy pattern & chain of responsibilities
Factory method, strategy pattern & chain of responsibilitiesFactory method, strategy pattern & chain of responsibilities
Factory method, strategy pattern & chain of responsibilities
 
Decomposing the Monolith using modern-day .NET and a touch of microservices
Decomposing the Monolith using modern-day .NET and a touch of microservicesDecomposing the Monolith using modern-day .NET and a touch of microservices
Decomposing the Monolith using modern-day .NET and a touch of microservices
 
My 70-480 HTML5 certification learning
My 70-480 HTML5 certification learningMy 70-480 HTML5 certification learning
My 70-480 HTML5 certification learning
 
Proxy pattern
Proxy patternProxy pattern
Proxy pattern
 
Proxy pattern
Proxy patternProxy pattern
Proxy pattern
 
SCWCD : Web tier design CHAP : 11
SCWCD : Web tier design CHAP : 11SCWCD : Web tier design CHAP : 11
SCWCD : Web tier design CHAP : 11
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWARE
 
Design Patterns - Part 2 of 2
Design Patterns - Part 2 of 2Design Patterns - Part 2 of 2
Design Patterns - Part 2 of 2
 
WPF - Controls & Data
WPF - Controls & DataWPF - Controls & Data
WPF - Controls & Data
 
A serverless IoT story from design to production and monitoring
A serverless IoT story from design to production and monitoringA serverless IoT story from design to production and monitoring
A serverless IoT story from design to production and monitoring
 

Último

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Último (20)

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 

Proxy design pattern

  • 1. Proxy Design pattern Control the access to your objects
  • 2. Motivation  The need to control the access to a certain object
  • 3. Intent  The Proxy pattern provides a surrogate or placeholder for another object to control access to it  This ability to control the access to an object can be required for a variety of reasons:  To hide information about the real object to the client  To perform optimization like on demand loading  To do additional house-keeping job like audit tasks  Proxy design pattern is also known as surrogate design pattern
  • 4. Context Sometimes a client object may not be able to access a service provider object (also referred to as a target object) by normal means. This could happen for a variety of reasons depending on:  The location of the target object  The target object may be present in a different address space in the same or a different computer.  The state of existence of the target object  The target object may not exist until it is actually needed to render a service or the object may be in a compressed form.  Special Behavior  The target object may offer or deny services based on the access privileges of its client objects. Some service provider objects may need special consideration when used in a multithreaded environment
  • 5. Solution In such cases, the Proxy pattern suggests using a separate object referred to as a proxy to provide a means for different client objects to access the target object in a normal, straightforward manner.  The Proxy object offers the same interface as the target object.  The Proxy object interacts with the target object on behalf of a client object and takes care of the specific details of communicating with the target object  Client objects need not even know that they are dealing with Proxy for the original object.  Proxy object serves as a transparent bridge between the client and an inaccessible remote object or an object whose instantiation may have been deferred.
  • 6. Implementation  UML class diagram for the Proxy Pattern
  • 7. Implementation The participants classes in the proxy pattern are:  Subject - Interface implemented by the RealSubject and representing its services. The interface must be implemented by the proxy as well so that the proxy can be used in any location where the RealSubject can be used  Proxy  Maintains a reference that allows the Proxy to access the RealSubject.  Implements the same interface implemented by the RealSubject so that the Proxy can be substituted for the RealSubject.  Controls access to the RealSubject and may be responsible for its creation and deletion.  Other responsibilities depend on the kind of proxy.  RealSubject - the real object that the proxy represents
  • 8. Applicability  Proxies are useful wherever there is a need for a more sophisticated reference to a object than a simple pointer or simple reference can provide  Use the Proxy Pattern to create a representative object that controls access to another object, which may be remote, expensive to create or in need of securing  There are several use-case scenarios that are often repeatable in practice
  • 9. Applicability  Remote Proxy  The remote proxy provides a local representation of the object which is present in the different address location  Virtual Proxy  delaying the creation and initialization of expensive objects until needed, where the objects are created on demand  Protection Proxy  The protective proxy acts as an authorization layer to verify if the actual user has access to appropriate content  Smart Reference  provides additional actions whenever a subject is referenced, such as counting the number of references to an object
  • 10. Applicability  Firewall Proxy  controls access to a set of network resources, protecting the subject from “bad” clients  Caching Proxy  Provides temporary storage for results of operations that are expensive. It can also allow multiple clients to share the results to reduce computation or network latency  Synchronization Proxy  provides safe access to a subject from multiple threads  Copy-On-Write Proxy  controls the copying of an object by deferring the copying of an object until it is required by a client. This is a variant of the Virtual Proxy  Complexity Hiding Proxy
  • 11. Example: Remote Proxy  Solves the problem when the real subject is a remote object. A remote object is object that exists outside of the current Java Virtual Machine whether it be in another JVM process on the same machine or a far machine accessible by network.  The Remote Proxy pattern enables communication with minimal modification to existing code  The Remote Proxy acts as a local representative to the remote object  The client call methods of the proxy  The proxy forwards the calls to the remote object  To the client, it appears as though it is communicating directly with the remote object
  • 13. Example: Remote Proxy public interface ISubject { public String doHeavyTask(String arguments); } public class RealSubject implements ISubject{ @Override public String doHeavyTask(String arguments) { //do the heavy task.. //generate results String results = new String("Results"); return results; } }
  • 14. Example: Remote Proxy public class Proxy implements ISubject{ @Override public String doHeavyTask(String arguments) { //start of the stub routine //pack arguments and generate the request.. //send the request and wait for the response //unpack results from the response String results = new String("Results"); //end of the stub routine return results; } }
  • 15. Example: Remote Proxy public class Skeleton { /* * */ public void receiveRequest(String request){ //unpack the request //object? RealSubject subject = new RealSubject(); //method? arguments? String result = subject.doHeavyTask("arguments"); //pack response with the result //send the response } }
  • 17. Example: Virtual Proxy  Solves the problems that arises while working directly with objects that are expensive to create, initialize and maintain in concern with time or memory consumption  In this situations the Virtual Proxy:  acts as a representative for an object that may be expensive to create  often defers the creation of the object until it is needed  also acts as a surrogate for the object before and while it is being created. After that, the proxy delegates requests directly to the RealSubject
  • 20. Example: Virtual Proxy class ImageProxy implements Icon { ImageIcon imageIcon; public int getIconWidth() { if (imageIcon != null) { return imageIcon.getIconWidth(); } else { return 800; } } public int getIconHeight() { if (imageIcon != null) { return imageIcon.getIconHeight(); } else { return 600; } } }
  • 21. Example: Virtual Proxy public void paintIcon(final Component c, Graphics g, int x, int y) { if (imageIcon != null) { imageIcon.paintIcon(c, g, x, y); } else { g.drawString("Loading CD cover, please wait...", x+300, y+190); if (!retrieving) { retrieving = true; retrievalThread = new Thread(new Runnable() { public void run() { try { imageIcon = new ImageIcon(imageURL, "CD Cover"); c.repaint(); } catch (Exception e) {} } }); retrievalThread.start(); } } }
  • 22. Example: Virtual Proxy  Refactoring the code: URL url = new URL("http://images.amazon.com/images/some_image.jpg"); Icon icon = new ImageIcon(url); Icon icon = new ImageProxy(url); int iconHeight = icon.getIconHeight(); int iconWidth = icon.getIconWidth(); icon.paintIcon(c, g, x, y);
  • 23. Related patterns Many design patterns can have similar or exactly same structure but they still differ from each other in their intent.  Adapter design pattern  Adapter provides a different interface to the object it adapts and enables the client to use it to interact with it, while proxy provides the same interface as the subject  Decorator design pattern  A decorator implementation can be the same as the proxy however a decorator adds responsibilities to an object while a proxy controls access to it
  • 25. “ Thank you for your attention ” Sashe Klechkovski December, 2013

Notas do Editor

  1. Ponekogas sejavuvapotrebata da kontroliramenekoj process kojtreba da se odvivaili da kontroliramepristap do nekojobjekt. Tukaimameednaslikakojaduri I kajnas e poznata, odnosnonanasitebabi I dedovci bi mu biladobropoznatadokolkugiprasame a toa e kakoodelprocesotnazapoznavanje I sklucuvanjenabrakporano. Slikataopisuva scenario nabracnointervjupomegumladozenecot I nevestatakoe se odvivaprekunekojatetkananevestatakakomedijatorilistrojnikkako so e poznatokajnas
  2. Ponekogas sejavuvapotrebata da kontroliramenekoj process kojtreba da se odvivaili da kontroliramepristap do nekojobjekt. Tukaimameednaslikakojaduri I kajnas e poznata, odnosnonanasitebabi I dedovci bi mu biladobropoznatadokolkugiprasame a toa e kakoodelprocesotnazapoznavanje I sklucuvanjenabrakporano. Slikataopisuva scenario nabracnointervjupomegumladozenecot I nevestatakoe se odvivaprekunekojatetkananevestatakakomedijatorilistrojnikkako so e poznatokajnas
  3. Proxy pattniovozmozuvakreiranje I predavanjenasurogatobjektnamestorealniotobjektilike go enkapsuliravistinskiot object za da ovozmozikontrolanapristapotkonnego.
  4. Koga bi bilakorisnaupotrebatana Proxy
  5. Complexity Hiding Proxy hides the complexity of and controls access to a complex set of classes. This is sometimes called the Facade Proxy for obvious reasons. The Complexity Hiding Proxy differs from the Facade Pattern in that the proxy controls access, while the Façade Pattern just provides an alternative interface.
  6. Slikata sketch 2 poednostavnatacistozapodsetuvanje. Vovedvoproblemotna Virtual proxy.
  7. Nakratkodekapostojatdrugi proxy implementacii koi resavaatdrugi problem. Vovedzosto Proxy nalikuvananekoidrugipaterni.