PROXY Matt Burden T-Kiang Tan Proxy (prok-se): An agent or substitute authorized to act for another SourceSource: Webster's Revised Unabridged Dictionary,

Slides:



Advertisements
Similar presentations
Socket Programming By Ratnakar Kamath. What Is a Socket? Server has a socket bound to a specific port number. Client makes a connection request. Server.
Advertisements

ECE122 L4: Creating Objects February 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 4 Creating and Using Objects.
Using Processing Stream. Predefined Streams System.in InputStream used to read bytes from the keyboard System.out PrintStream used to write bytes to the.
CS 206 Introduction to Computer Science II 01 / 21 / 2009 Instructor: Michael Eckmann.
Unit 181 Recursion Definition Recursive Methods Example 1 How does Recursion work? Example 2 Problems with Recursion Infinite Recursion Exercises.
Exception examples. import java.io.*; import java.util.*; class IO { private String line; private StringTokenizer tokenizer; public void newline(DataInputStream.
Chapter 3 Using Classes and Objects. Creating Objects A variable holds either a primitive type or a reference to an object A class name can be used as.
Proxy Pattern Ralph Rodkey Josh Voils. Proxy Intent  Metsker and GoF:  To provide a surrogate, or placeholder, for another object to control access.
String Tokenization What is String Tokenization?
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.
Java Review Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Odds and Ends Strings (from Chapter 9) StringTokenizer.
References, Aliases, Garbage Collection and Packages Packages and Importing Classes Reading for this Lecture: L&L, Familiarize yourself with.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Proxy Design Pattern (1) –A structural design pattern.
Io package as Java’s basic I/O system continue’d.
Web Security Programming I Building Security in from the Start Except where otherwise noted all portions of this work are Copyright (c) 2007 Google and.
Smart Reference Proxy Provides additional actions whenever an object is referenced (e.g., counting the number of references to the object) Firewall Proxy.
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.
Java Packages and Libraries M Taimoor Khan
The Java Programming Language
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Processes & Threads Bahareh Goodarzi. Single & Multiple Thread of control code files data code files data.
In the name of Allah The Proxy Pattern Elham moazzen.
CS 206 Introduction to Computer Science II 09 / 10 / 2009 Instructor: Michael Eckmann.
1 Recitation 8. 2 Outline Goals of this recitation: 1.Learn about loading files 2.Learn about command line arguments 3.Review of Exceptions.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
1 Week 12 l Overview of Streams and File I/O l Text File I/O Streams and File I/O.
CS100A, Fall 1997, Lecture 91 CS100A, Fall 1997 Lecture 9, Tuesday, 30 September Input/Output & Program Schema System.in, class Text, Some basic data processing,
1 StringTokenization Overview l StringTokenizer class l Some StringTokenizer methods l StringTokenizer examples.
Documentation Dr. Andrew Wallace PhD BEng(hons) EurIng
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.
02 - Structural Design Patterns – 2 Moshe Fresko Bar-Ilan University תשס"ח 2008.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
Proxy.
Proxy Design Pattern By:Diksha Agarwal.
Files and Streams CS /02/05 L7: Files Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
Java for C++ Programmers A Brief Tutorial. Overview Classes and Objects Simple Program Constructors Arrays Strings Inheritance and Interfaces Exceptions.
EE 422C Day 2 Java, Eclipse. Copyright Pearson Education, 2010 Based on slides bu Marty Stepp and Stuart Reges from
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 9 GEORGE KOUTSOGIANNAKIS Copyright: 2014 Illinois Institute of Technology- George Koutsogiannakis 1.
State Design Pattern. Behavioral Pattern Allows object to alter its behavior when internal state changes Uses Polymorphism to define different behaviors.
String line = console.readLine() StringTokenizer st = new StringTokenizer(line)
Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Chapter 3: Using Classes and Objects Coming up: Creating Objects.
Documentation Javadocs. Design/Documentation An essential ingredient of good Object Oriented programming is known as design by contract. This means that.
The Proxy Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Singleton Pattern. Problem Want to ensure a single instance of a class, shared by all uses throughout a program Context Need to address initialization.
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
Overview Project 2 JFileChooser StringTokenizers Vectors/arrays.
Interactive Programs Programs that get input from the user 1 In PowerPoint, click on the speaker icon then click the "Play" button to hear the narration.
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 4 GEORGE KOUTSOGIANNAKIS Copyright: 2016 Illinois Institute of Technology/George Koutsogiannakis 1.
Software Design and Architecture Muhammad Nasir Structural Design Patterns
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
DYNAMIC MEMORY ALLOCATION. Disadvantages of ARRAYS MEMORY ALLOCATION OF ARRAY IS STATIC: Less resource utilization. For example: If the maximum elements.
Threads in Java Two ways to start a thread
Introduction to programming in java
Chapter 4: Writing Classes
Dynamic Proxy Proxy: Addition to the Java 1.3 reflection package:
L3. Necessary Java Programming Techniques
L3. Necessary Java Programming Techniques
Chapter Four: DFA Applications
Arrays and Collections
OBJECT ORIENTED PROGRAMMING I LECTURE 9 GEORGE KOUTSOGIANNAKIS
File Input and Output.
Software Design Lecture : 38.
Java Coding 6 David Davenport Computer Eng. Dept.,
Presentation transcript:

PROXY Matt Burden T-Kiang Tan Proxy (prok-se): An agent or substitute authorized to act for another SourceSource: Webster's Revised Unabridged Dictionary, © 1996 MICRA, Inc.

Pattern Type: Object Structural Intent: Provide a surrogate or placeholder for another object to control access to it.

Examples Debit Card (represents the cash in your account when making a purchase). Proxy voting (like an absentee ballot or stock owner proxy).

Design Issues In terms of time and resources (memory), it is expensive to instantiate objects before we use them. May need to protect access to an object. Contexts:

Proxy allows for objects to be created on demand. Proxy uses another object in place or a stand-in for the actual object. Proxy can act just like the object and takes care of instantiating it when required. Proxy Design Solutions

Absentee Ballot Proxy

Debit Card Example

Debit Card UML

Card Swiper UML

Proxy Consequences Can hide the fact that an object resides in a different address space (remote). Can enhance optimization by creating objects on demand (virtual). Can act as a pointer (smart-reference). Can control access to the original object (protection).

Proxy Benefits Smaller memory footprint—loads as needed Changes can be made to the actual object with making any changes to the application (i.e. swapping pictures).

Proxy Liabilities When proxy is first used, user may have to wait for file to load. Work Around: Have a process load it when application is started. Code management becomes more complicated (more files). Work Around: Document source code and processes.

Questions?

//Title: UsingPlastic //Version: //Copyright: Copyright (c) 1999 //Author: T-Kiang Tan //Company: University of Chicago: CSPP 523 //Description: Demo. package UsingPlastic; import java.util.*; //Using ArrayList and HashTable public class PlasticProxy implements PlasticProxyInterface { ArrayList list; String[] card_types; public PlasticProxy(String[] cardTypes) { card_types = cardTypes; list = new ArrayList(card_types.length); } public String getApproval(String card_type)

{ System.out.println("****PlasticProxy: Connecting to " + card_type); Plastic plastic= new Plastic(card_type); System.out.println("****PlasticProxy: " + plastic.initialize()); System.out.println("****PlasticProxy: Requesting for approval from " + card_type); System.out.println("****PlasticProxy: " + plastic.getApproval(card_type)); return("Transaction has been approved"); } public String initialize() { System.out.println("****PlasticProxy: Initializing proxy. done only once"); return(new String("PlasticProxy is initialized")); }

//Title: UsingPlastic //Version: //Copyright: Copyright (c) 1999 //Author: T-Kiang Tan //Company: University of Chicago: CSPP 523 //Description: Demo. package UsingPlastic; public class Plastic implements PlasticProxyInterface { String card; public Plastic(String card_type){ card = card_type;} public String getApproval(String card_type) { System.out.println("******" + card + ": Request is in progress"); return(card + " - Transaction Approved"); }

public String initialize() { System.out.println("******" +card + ": Initializing is in progress"); return("Connection Established with " + card); } //Title: UsingPlastic //Version: //Copyright: Copyright (c) 1999 //Author: T-Kiang Tan //Company: University of Chicago: CSPP 523 //Description: Demo. package UsingPlastic; public interface PlasticProxyInterface { public String getApproval(String card_type); public String initialize(); }

//Title: UsingPlastic //Version: //Copyright: Copyright (c) 1999 //Author: T-Kiang Tan //Company: University of Chicago: CSPP 523 //Description:Demo. package UsingPlastic; import java.awt.*; import java.awt.event.*; import javax.swing.*;

public class UsingPlastic { public static void main(String[] card_types) { String input = " "; String[] tokens; int i = 0; PlasticProxy plasticproxy = new PlasticProxy(card_types); System.out.println("**UsingPlastic: " + plasticproxy.initialize()); while (true) { System.out.println("Main: Please slide the card when ready:"); for(i = 0; i < card_types.length; i++) System.out.println("Main: " + (i+1) + ". " + card_types[i]); System.out.print("Main: Which card did you slide again? >> "); input = ParserUtils.getKeyInput();

if(input.equalsIgnoreCase("exit")) break; Integer integer = new Integer(input); i = integer.intValue() - 1; System.out.println("#########################"); System.out.println("**UsingPlastic: Requesting for approval from " + card_types[i]); System.out.println("**UsingPlastic: " + plasticproxy.getApproval(card_types[i]) + " by " + card_types[i]); System.out.println("#########################"); } System.out.println("Main: Thanks you for using the Proxy Presentation Demo"); System.out.println("Main: Matt Burden and T-Kiang Tan"); System.out.println("Main: Winter 2002"); }

//Parser utils--this is our first class which does not have a main method. Its purpose it to serve as a warehouse of related methods that can be accessed from any main//method. This class contains methods useful for writing a parser. // 1. public static String getKeyInput(){ //blocks program until user enters zero or more characters followed by a "enter“ and returns input to calling program // 2. public static String[] getTokens(String input){ //takes String and breaks into tokens defined by one or more white spaces and return array of String each element of which is an individual tokenpackage UsingPlastic; import java.io.*; import java.util.*; class ParserUtils{public static String getKeyInput(){ String input = null; try{BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); input = in.readLine();} catch (IOException ioe){System.out.println(ioe);} return input; } public static String[] getTokens(String input){ int i = 0;

StringTokenizer st = new StringTokenizer(input); int numTokens = st.countTokens(); String[] tokenList = new String[numTokens]; while (st.hasMoreTokens()){ tokenList[i] = st.nextToken(); i++;} return(tokenList); }}