1 The Proxy Design Pattern Problem: Defer the cost of object creation and init. until actually used Applicability (possible contexts): – Virtual Proxy:

Slides:



Advertisements
Similar presentations
What Are Design Patterns and Why Do I Need Them? Software professionals may be familiar with the term "Design Patterns," but many have no idea of where.
Advertisements

Design Patterns based on book of Gang of Four (GoF) Erich Gamma, Richard Helm, Ralph Johnson, and John VlissidesGang of Four (GoF) Elements of Reusable.
1 Patterns in Object Oriented Programming A Concise Introductory Presentation Amnon H. Eden Tel Aviv University
Lightweight Remote Procedure Call BRIAN N. BERSHAD THOMAS E. ANDERSON EDWARD D. LAZOWSKA HENRY M. LEVY Presented by Wen Sun.
Design Patterns David Talby. This Lecture Representing other objects Proxy, Adapter, Façade Re-routing method calls Chain of Responsibility Coding partial.
Design Patterns Copyright © Vyacheslav Mukhortov, Nikita Nyanchuk-Tatarskiy, Copyright © INTEKS LLC,
Proxy Pattern Ralph Rodkey Josh Voils. Proxy Intent  Metsker and GoF:  To provide a surrogate, or placeholder, for another object to control access.
Lightweight Remote Procedure Call Brian N. Bershad, Thomas E. Anderson, Edward D. Lazowska, Henry M. Levy ACM Transactions Vol. 8, No. 1, February 1990,
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0More on Structural Patterns - Page L7-1 PS95&96-MEF-L14-1 Dr. M.E. Fayad Creationa.
Design Patterns: Proxy Jason Jacob. What is a Proxy? A Proxy is basically a representative between the Client and the Component. It gives the Client a.
Design Patterns Part IV (TIC++V2:C10) Yingcai Xiao 10/01/08.
Algorithm Programming Structural Design Patterns Bar-Ilan University תשס " ו by Moshe Fresko.
PROXY Matt Burden T-Kiang Tan Proxy (prok-se): An agent or substitute authorized to act for another SourceSource: Webster's Revised Unabridged Dictionary,
Design Patterns David Talby. This Lecture n The rest of the pack u Working over a network F Proxy, State, Chain of Responsibility u Working with external.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Proxy Design Pattern (1) –A structural design pattern.
Proxy Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Client/Server Software Architectures Yonglei Tao.
Smart Reference Proxy Provides additional actions whenever an object is referenced (e.g., counting the number of references to the object) Firewall Proxy.
Design Patterns David Talby. This Lecture n Re-Routing Method Calls u Proxy, Chain of Responsibility n Working with external libraries u Adapter, Façade.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
Team 5: The Infinite Loops Gloria Berumen Patricia Martinez Jose Roberto Salcido Michelle Soto Jose Luis Yanez Omar Zorrilla Design Pattern.
In the name of Allah The Proxy Pattern Elham moazzen.
Object Oriented Software Engineering Chapter 16 and 17 review 2014/06/03.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Computer Science 209 The Proxy Pattern. Delayed Instantiation if (obj == null) obj = It ’ s expensive to load an image If the user never looks at an image,
Structural Design Patterns
More Design Patterns Horstmann ch.10.1,10.4. Design patterns Structural design patterns –Adapter –Composite –Decorator –Proxy Behavioral design patterns.
Where Do Surrogates Fit into This Proxy Pattern Observer Pattern Visitor Pattern By Kurt Rehwinkel.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns V More Structural Patterns.
02 - Structural Design Patterns – 2 Moshe Fresko Bar-Ilan University תשס"ח 2008.
Design Patterns Structural Patterns. Adapter Convert the interface of a class into another interface clients expect Adapter lets classes work together.
The Proxy Pattern SE-2811 Dr. Mark L. Hornick 1. The Proxy Pattern has many variations, but in general: The Proxy Pattern uses an proxy object as a surrogate.
Proxy, Observer, Symbolic Links Rebecca Chernoff.
08 - StructuralCSC4071 Structural Patterns concerned with how classes and objects are composed to form larger structures –Adapter interface converter Bridge.
Structural Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
Proxy.
Proxy Design Pattern By:Diksha Agarwal.
CS616: Software Engineering Spring 2009 Design Patterns Sami Taha.
Processes and Virtual Memory
The Mach System Silberschatz et al Presented By Anjana Venkat.
1 Advanced Object-oriented Design – Principles and Patterns Structural Design Patterns.
Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it by creating a representative object.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Chapter 8 Object Design Reuse and Patterns. More Patterns Abstract Factory: Provide manufacturer independence Builder: Hide a complex creation process.
Proxy Pattern. What’s a Proxy? A remote proxy acts as a local representative of a remote object Remote Object: instantiated in a different JVM heap (a.
The Proxy Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Proxy. PBA WEB – BEWP 2 The Proxy pattern What is a Proxy? A Proxy is a ”placeholder” for a different object, to which we will not allow direct access.
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 Broker Design Patterns: Adapters and Proxy.
Week 9, Day 1 Proxy SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
Software Design and Architecture Muhammad Nasir Structural Design Patterns
1/23/2018 Design Patterns David Talby.
Design Patterns Lecture part 2.
Dynamic Proxy Proxy: Addition to the Java 1.3 reflection package:
Decorator Design Pattern
How to be a Good Developer
Design Patterns Satya Puvvada Satya Puvvada.
Frameworks And Patterns
Informatics 122 Software Design II
UNIT-III Structural Design Patterns
Fast Communication and User Level Parallelism
Presented by Neha Agrawal
Prof. Leonardo Mostarda University of Camerino
High Performance Computing
Informatics 122 Software Design II
Software Design Lecture : 38.
15. Proxy SE2811 Software Component Design
Proxy Pattern Definition of “Proxy”: Authority or power to act for another Original Gang of Four pattern, much used Stands in for a “real object” (similar.
Software Design Lecture 10.
Iterator Design Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014
Presentation transcript:

1 The Proxy Design Pattern Problem: Defer the cost of object creation and init. until actually used Applicability (possible contexts): – Virtual Proxy: Create an expensive object on demand (lazy construction) – Cache Proxy (PLoPD 2): Hold results temporarily – Remote Proxy: Use a local representative for a remote object (different address space) – Protection Proxy: Control access to shared object

Intent and Motivation Intent – Provide a surrogate of placeholder for another object to control access to it. Motivation – Deferring object creation – lazy evaluation, on demand creation – Separate this from the actual object Client treats the Proxy as if the real object was created Proxy interprets the on-demand evaluation policy.

Proxy Motivation

Proxy Motivation -2

Proxy Applicability Remote proxy provides a local representation of the remote object in different address spaces Virtual proxy creates expensive objects on demand Protection proxy controls access to the original object, for instance when implementing access rights to objects in a separate layer Smart reference instead of a simple pointer to count object references including – Counting references – Loading persistent objects into memory on first reference – Checking object locking on access

Proxy Structure

Proxy Structure - 2

Proxy Participants Proxy (ImageProxy) – Maintains a reference by which to access the real subject. – Provides an interface identical to Subject, so it can be substituted for the real subject – Controls access to the real subject and may be responsible for creating it. – Also: For remote proxy – encoding and decoding messages (I.e., RPC) For virtual proxy – caching the real subject For protection proxy – check callers access rights. Subject (Graphic) – Defines the common interface for RealSubject and Proxy so that a Proxy can be used anywhere a RealSubject can. RealSubject (Image) – defines, the real object that the proxy represents.

Proxy Collaborations – Proxy forwards requests to RealSubject when appropriate, depending on the kind of proxy. – May perform some operations before like a mediator, or after. Consequences – Remote proxy – hides the fact that RealSubject is remote – Virtual proxy – optimizes such as on-demand creation – Protection proxy and smart reference – allow additional housekeeping chores when subject is accessed. – Copy-on-write – postpones creation of a copy of an object until it is necessary (if at all changed from the original).

10 Sample Context: Word Processor Paragraph Document Paragraph Image

11 Forces 1. The image is expensive to load 2. The complete image is not always necessary 2MB 2KB optimize!

12 A Bad Solution Obviously, the document should not be aware to the optimization, nor to the image contents, etc. document::draw() { switch (glyph.type) { case image: if (cannot_optimize) load_full_image(); else optimize(glyph); break; case paragraph:...

Applicability Behaviour of an object depends on its state, and it must change its behaviour depending on that state. Operations have large multipart conditional statements...

14 Proxy Solution (example) Image Proxy || file_name : String || get_image( ) Draft( ) DrawDetailed( ) Document Real Image || ImageData Glyph Draw( ) 0..n real_image Solution: Provide a “surrogate” or place-holder which provides transparent access to another object

15 Proxy Solution (example): Object Diagram aDocument image Proxy theBitmap: RealImage 1: DrawDetailed ( ) 3: new (fileName) 2: get_image ( ) 4: DrawDetailed( )

16 Proxy Solution (general form) RealSubject Request( ) Proxy Request( ) Subject Request( ) client realSubject

Proxy Motivation 1

Proxy Motivation 2

Proxy Structure Provide a surrogate or placeholder for another object to control access to it