Proxy Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.

Slides:



Advertisements
Similar presentations
Chapter 5: The Singleton Pattern
Advertisements

Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
Design Patterns CMPS Design Patterns Consider previous solutions to problems similar to any new problem ▫ must have some characteristics in common.
Design Patterns Copyright © Vyacheslav Mukhortov, Nikita Nyanchuk-Tatarskiy, Copyright © INTEKS LLC,
DESIGN PATTERNS OZGUR RAHMI DONMEZ.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Freenet A Distributed Anonymous Information Storage and Retrieval System I Clarke O Sandberg I Clarke O Sandberg B WileyT W Hong.
Design Patterns Part IV (TIC++V2:C10) Yingcai Xiao 10/01/08.
Algorithm Programming Structural Design Patterns Bar-Ilan University תשס " ו by Moshe Fresko.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Command Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Façade Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
What Is a Factory Pattern?.  Factories are classes that create or construct something.  In the case of object-oriented code languages, factories construct.
Client/Server Software Architectures Yonglei Tao.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 2: Modelling.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
BASE CLASSES AND INHERITANCE CHAPTER 4. Engineer Class.
Smart Reference Proxy Provides additional actions whenever an object is referenced (e.g., counting the number of references to the object) Firewall Proxy.
Observer Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
1 The Proxy Design Pattern Problem: Defer the cost of object creation and init. until actually used Applicability (possible contexts): – Virtual Proxy:
SAMANVITHA RAMAYANAM 18 TH FEBRUARY 2010 CPE 691 LAYERED APPLICATION.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
Data structures and algorithms in the collection framework 1 Part 2.
1 C - Memory Simple Types Arrays Pointers Pointer to Pointer Multi-dimensional Arrays Dynamic Memory Allocation.
Patterns and Reuse. Patterns Reuse of Analysis and Design.
In the name of Allah The Proxy Pattern Elham moazzen.
New features for CORBA 3.0 by Steve Vinoski Presented by Ajay Tandon.
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
© 2005 Prentice Hall10-1 Stumpf and Teague Object-Oriented Systems Analysis and Design with UML.
Chain of Responsibility Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Pipes & Filters Architecture Pattern Source: Pattern-Oriented Software Architecture, Vol. 1, Buschmann, et al.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
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.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
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.
DOUBLE INSTANCE LOCKING A concurrency pattern with Lock-Free read operations Pedro Ramalhete Andreia Correia November 2013.
The Singleton Pattern SE-2811 Dr. Mark L. Hornick 1.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Dale Roberts Object Oriented Programming using Java - Final and Static Keywords Dale Roberts, Lecturer Computer Science, IUPUI
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Refactoring Agile Development Project. Lecture roadmap Refactoring Some issues to address when coding.
The Singleton Pattern (Creational)
The Proxy Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
Internet Computing Module II. Syllabus Creating & Using classes in Java – Methods and Classes – Inheritance – Super Class – Method Overriding – Packages.
Software Design and Architecture Muhammad Nasir Structural Design Patterns
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Cofax Scalability Document Version Scaling Cofax in General The scalability of Cofax is directly related to the system software, hardware and network.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Modularity Most useful abstractions an OS wants to offer can’t be directly realized by hardware Modularity is one technique the OS uses to provide better.
EECE 310: Software Engineering
Distributed Shared Memory
The Singleton Pattern SE-2811 Dr. Mark L. Hornick.
Lecture 25 More Synchronized Data and Producer/Consumer Relationship
Advanced Programming Behnam Hatami Fall 2017.
Git CS Fall 2018.
SAMANVITHA RAMAYANAM 18TH FEBRUARY 2010 CPE 691
Software Design Lecture : 38.
Presentation transcript:

Proxy Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.

Problem You need to control access to an object

Solution Create a Proxy object that implements the same interface as the real object The Proxy object (usually) contains a reference to the real object Clients are given a reference to the Proxy, not the real object All client operations on the object pass through the Proxy, allowing the Proxy to perform additional processing

Solution

Consequences Provides an additional level of indirection between client and object that may be used to insert arbitrary services Proxies are invisible to the client, so introducing proxies does not affect client code

Known Uses: Java Collections Read-only Collections –Wrap collection object in a proxy that only allows read-only operations to be invoked on the collection –All other operations throw exceptions –List Collections.unmodifiableList(List list); Returns read-only List proxy Synchronized Collections –Wrap collection object in a proxy that ensures only one thread at a time is allowed to access the collection –Proxy acquires lock before calling a method, and releases lock after the method completes –List Collections.synchronizedList(List list); Returns a synchronized List proxy

Known Uses: Distributed Objects The Client and Real Subject are in different processes or on different machines, and so a direct method call will not work The Proxy's job is to pass the method call across process or machine boundaries, and return the result to the client (with Broker's help)

Known Uses: Secure Objects Different clients have different levels of access privileges to an object Clients access the object through a proxy The proxy either allows or rejects a method call depending on what method is being called and who is calling it (i.e., the client's identity)

Known Uses: Lazy Loading Some objects are expensive to instantiate (i.e., consume lots of resources or take a long time to initialize) Rather than instantiating an expensive object right away, create a proxy instead, and give the proxy to the client The proxy creates the object on demand when the client first uses it If the client never uses the object, the expense of creating it is never incurred A hybrid approach can be used, where the proxy implements some operations itself, and only needs to create the real object if the client calls one of the operations it doesn't implement Proxies must store whatever information is needed to create the object on-the-fly (file name, network address, etc.)

Known Uses: Lazy Loading Examples Object-Oriented Databases –Graph of objects stored on disk –Objects contain references to each other –Load proxies initially, and only load the real object from disk if a method is actually called on it Resource Conservation –If you need to store thousands of objects in memory at once, proxies can be used to save memory by only loading objects that are actually used –Objects that are used can be unloaded after awhile, freeing up memory Word Processor –Documents that contain lots of multimedia objects should still load fast –Create proxies that represent large images, movies, etc., and only load objects on demand as they become visible on the screen (only a small part of the document is visible at a time)

Known Uses: Copy-on-Write Multiple clients share the same object as long as nobody tries to change it When a client attempts to change the object, they get their own private copy of the object Read-only clients continue to share the original object, while writers get their own copies Allows resource sharing, while making it look like everyone has their own object A String class could use this approach to optimize copying To make this work, clients are given proxies rather than direct references to the object When a write operation occurs, a proxy makes a private copy of the object on-the-fly to insulate other clients from the changes

Known Uses: Copy-on-Write

Known Uses: Reference Counting Proxies maintain the reference count inside the object The last proxy to go away is responsible for deleting the object (i.e., when the reference count goes to 0, delete the object)

Proxy vs. Decorator The Proxy pattern is very similar in structure to the Decorator pattern. Both patterns create a “wrapper” around another object. (Adapter is a third kind of “wrapper”, but is clearly different from Decorator and Proxy because an adapter has a different interface than the wrapped object). Here are some differences between the two patterns: –The intents of the patterns are different. Decorator is used to add responsibilities to an object (without using inheritance). A Proxy is used to “control access” to an object. Rather than adding functionality, a Proxy might actually prevent access to functionality. Read-only collections, Secure objects –Decorators are often organized into chains where each decorator adds a separate responsibility. Proxies are usually not organized into chains (although they could be). –A Decorator always stores a reference to the wrapped object; a Proxy may or may not, depending on what it does Distributed objects (proxy never stores direct object reference) Lazy Loading (proxy sometimes stores a direct object reference)