JIT in Premanufacturing at North American Gear (NAG) Part

Download Report

Transcript JIT in Premanufacturing at North American Gear (NAG) Part

PROXY
Proxy (prok-se): An agent or substitute
authorized to act for another
Matt Burden
T-Kiang Tan
Source: 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
Contexts:
• 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.
Proxy Design Solutions
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.
Absentee Ballot Proxy
Debit Card Example
Debit Card UML
Card Swiper UML
Card Swiper 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); }}