Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 210 Proxy Pattern Nov 14 th, 2006. Revisit the Gumball machine example The same example covered in the State pattern Now we want to add some monitor.

Similar presentations


Presentation on theme: "CS 210 Proxy Pattern Nov 14 th, 2006. Revisit the Gumball machine example The same example covered in the State pattern Now we want to add some monitor."— Presentation transcript:

1 CS 210 Proxy Pattern Nov 14 th, 2006

2 Revisit the Gumball machine example The same example covered in the State pattern Now we want to add some monitor a collection of Gumball machines

3 Gumball Class

4 Gumball Monitor

5 Run the monitor Look at Eclipse code.

6 Role of the remote Proxy

7 RMI Detour in looking at Proxy Pattern

8 Remote Methods 101

9 How the method call happens Client calls method

10 Client Helper forwards to service helper

11 Service helper calls the real object

12 Real object returns result

13 Service helper forwards result to client helper

14 Client helper returns result to client

15

16 Steps in using Java RMI

17 Additional steps

18 STEP 1 Remote Interface

19 STEP 1 Remote Interface

20 STEP 2 Remote Implementation

21 STEP 2 Remote Implementation

22 STEP 3 Create Stubs & Skeletons

23

24

25

26 Client talks to the stub

27 Hooking up client and server objects

28

29

30 Back to Gumball machine problem

31 Gumball Machine remote interface import java.rmi.*; public interface GumballMachineRemote extends Remote { public int getCount() throws RemoteException; public String getLocation() throws RemoteException; public State getState() throws RemoteException; }

32 State interface extends Serializable import java.io.*; public interface State extends Serializable { public void insertQuarter(); public void ejectQuarter(); public void turnCrank(); public void dispense(); }

33 Use of keyword “transient” public class NoQuarterState implements State { transient GumballMachine gumballMachine; public NoQuarterState(GumballMachine gumballMachine) { this.gumballMachine = gumballMachine; } public void insertQuarter() { System.out.println("You inserted a quarter"); gumballMachine.setState(gumballMachine.getHasQuarterState()); } // other methods } The use of transient to to ensure that the seriolzation does not involve this object as well.

34 More of the implementation… Look at Eclipse for implementation of: GumballMachineRemote GumballTestDrive GumballMonitor Client GumballMonitor

35 Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it. The proxy pattern is used to create a representative object that controls access to another object, which may be remote, expensive to create or in need of securing.

36 Proxy Class Diagram


Download ppt "CS 210 Proxy Pattern Nov 14 th, 2006. Revisit the Gumball machine example The same example covered in the State pattern Now we want to add some monitor."

Similar presentations


Ads by Google