Proxy Pattern Ralph Rodkey Josh Voils. Proxy Intent  Metsker and GoF:  To provide a surrogate, or placeholder, for another object to control access.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

Computer Science 209 Images and GUIs. Working with Java Colors The class java.awt.Color includes constants, such as Color.red, for some commonly used.
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
Examples. // A simple Frame with Rectangle Inside import java.awt.*; import javax.swing.*; import java.awt.geom.*; // For Shapes class rectComponent extends.
Topic 10 Java Memory Management. 1-2 Memory Allocation in Java When a program is being executed, separate areas of memory are allocated for each class.
CS 210 Proxy Pattern Nov 14 th, Revisit the Gumball machine example The same example covered in the State pattern Now we want to add some monitor.
Design Patterns David Talby. This Lecture Representing other objects Proxy, Adapter, Façade Re-routing method calls Chain of Responsibility Coding partial.
The Proxy Design Pattern By Rees Byars. What is a Proxy?  An entity that acts on behalf of another entity  Voting by Proxy  Debit Cards.
Decorator Josh Voils and Ralph Rodkey. GoF Definition of Intent Attach additional responsibilities to an object dynamically Provide an alternative to.
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.
1Futures Futures contract –an agreement traded on an organized exchange to buy or sell assets (commodities or shares) at a fixed price but to be delivered.
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,
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Proxy Design Pattern (1) –A structural design pattern.
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
GUI Tutorial Images. Useful Info – not on final exam.
Proxy Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Chapter 11 Proxy Summary prepared by Kirk Scott 1.
Client/Server Software Architectures Yonglei Tao.
OOP Languages: Java vs C++
1 Interface Types & Polymorphism & introduction to graphics programming in Java.
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.
Applets Chapter 17.  Java’s big splash onto the scene came in the mid 90’s. The people at Sun Microsystems had managed to work java programs into Web.
1 The Proxy Design Pattern Problem: Defer the cost of object creation and init. until actually used Applicability (possible contexts): – Virtual Proxy:
Team 5: The Infinite Loops Gloria Berumen Patricia Martinez Jose Roberto Salcido Michelle Soto Jose Luis Yanez Omar Zorrilla Design Pattern.
Design Patterns Part two. Structural Patterns Concerned with how classes and objects are composed to form larger structures Concerned with how classes.
GUI programming Graphical user interface-based programming.
Unit 6 Proxy Summary prepared by Kirk Scott 1. Design Patterns in Java Chapter 11 Proxy Summary prepared by Kirk Scott 2.
In the name of Allah The Proxy Pattern Elham moazzen.
The Drawing program – Java Applets
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,
More Design Patterns Horstmann ch.10.1,10.4. Design patterns Structural design patterns –Adapter –Composite –Decorator –Proxy Behavioral design patterns.
 GUI – Graphic User Interface  Up to now in the programs we have written all output has been sent to the standard output device i.e.: the DOS console.
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.
Proxy, Observer, Symbolic Links Rebecca Chernoff.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
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.
Unit 6 Proxy Summary prepared by Kirk Scott 1. Design Patterns in Java Chapter 11 Proxy Summary prepared by Kirk Scott 2.
Proxy.
Proxy Design Pattern By:Diksha Agarwal.
Topic 13 List Boxes. JList Generates an ListSelectionEvent Event monitored by ListSelectionListener ListSelectionListener invokes method valueChanged.
Computer Science 209 The Adapter Pattern. The Context of the Adapter Pattern I want to use an existing class (the adaptee) without modifying it The context.
Practical Session 10: Animation. Animation kinds There are three basic kinds of animation: 1. Moving object 2. Changing pictures 3. Combination of 1 and.
Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it by creating a representative object.
The Proxy Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Object Oriented Programming in C++ Chapter 7 Dynamic Binding.
Software Design and Architecture Muhammad Nasir Structural Design Patterns
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
1/23/2018 Design Patterns David Talby.
Scope and Code Generation
Java Programming Language
Dynamic Proxy Proxy: Addition to the Java 1.3 reflection package:
How to be a Good Developer
Distributed Computing, M. L. Liu
Distributed Systems - Comp 655
Distributed Computing, M. L. Liu
Algonquin College Virtual Methods (Java) in Object-Oriented Programming (also call Polymorphism) Created by Rex Woollard Use PageUp and PageDown to move.
Java applets 1/3/2019.
Computer Science 209 The Adapter Pattern.
Software Design Lecture : 38.
עקרונות תכנות מונחה עצמים תרגול 7: אנימציה
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.
CS 151: Object-Oriented Design October 8 Class Meeting
Presentation transcript:

Proxy Pattern Ralph Rodkey Josh Voils

Proxy Intent  Metsker and GoF:  To provide a surrogate, or placeholder, for another object to control access to it

Proxy Uses  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

Proxy Uses – Cont.  Smart reference – A replacement for a bare pointer that performs additional actions when an object is accessed  Tracks the number of references to an object so it can be freed automatically when unneeded  Load a persistent object into memory when it’s first referenced  Mutexing the real object to ensure synchronicity

The ImageProxy example  Metsker and the GoF both use the ImageProxy example  An example of a Virtual Proxy

What the ImageProxy does  If we were to implement a picture browser, loading all of the images at runtime would incur a large memory cost  Solution: Use a small proxy object to be a placeholder, and let it load the actual image when requested

 We’ll use ImageIcons and Jlabels to display images ImageIcon i = new ImageIcon("Fest.jpg"); JLabel l = new JLabel(i);

import java.awt.*; import javax.swing.*; public class ImageIconLoader extends ImageIcon implements Runnable { static final ImageIcon ABSENT = new ImageIcon("absent.jpg"); static final ImageIcon LOADING = new ImageIcon("loading.jpg"); protected String filename; protected JFrame callbackFrame; public ImageIconLoader(String filename) { super(ABSENT.getImage()); this.filename = filename; } public void load(JFrame callbackFrame) { // challenge! } public void run() { // challenge! }

Challenge!  Implement:  int getIconHeight()  int getIconWidth()  void paintIcon(Component c, Graphics h, int x, int y)

Solution public void load(JFrame callbackFrame) { this.callbackFrame = callbackFrame; setImage(LOADING.getImage()); callbackFrame.repaint(); new Thread(this).start(); } public void run() { setImage(new ImageIcon(filename).getImage()); callbackFrame.pack(); }

Questions