Presentation is loading. Please wait.

Presentation is loading. Please wait.

Message Forwarding Semi-automatic proxy delegation.

Similar presentations

Presentation on theme: "Message Forwarding Semi-automatic proxy delegation."— Presentation transcript:

1 Message Forwarding Semi-automatic proxy delegation

2 What is a proxy? An element that represents another element Example: –Proxy vote – slip that is sent to a central authority in lieu of appearing and voting in person. The proxy vote represents the vote of the individual. –proxy delegate – simpler interface to a complex system

3 Bridge Pattern client with an interface server that implements the interface a means of communicating between the client and the server. The Goal is to have transparent distributed applications. Key for using RMI.

4 What is message forwarding? A message is passed from one place to another. In OOP Message Forwarding means: –Taking a method invocation and forwarding it to another instance.

5 Example class Mammal { public boolean hasHair() { return true; }

6 Movable class class Movable { int x, int y; public void move(int _x, int _y) { x = _x; y = _y; }

7 MovableMammal class MovableMammal { Movable m; Mammal mm; MovableMammal(Movable _m, Mammal _mm) { m = _m; mm = _mm; }.....

8 MovableMammal... public void move(int x, int y) { m.move(x, y); } public boolean hasHair() { return mm.hasHair(); }

9 UML the proxy uses the implementation of another class uses delegator delegatee e.g., MovableMammal

10 What is a static proxy degation? Have method invocations that are checked at compile time. Adding methods to the delegatees does NOT mean that methods will appear in the proxy.

11 What is dynamic delegation? New methods in the delegatee automatically appear available in the proxy at run-time. New feature for JDK 1.3 Not type safe. Exceptions can be thrown. For example: using reflection to invoke a string on an instance.

12 Semi-automatic Static Delegation Compile-time checks for type safety. Delgatee changes are discovered using introspection and cause a resynthesis of the proxy code. process of Java source code synthesis that occurs at a pre-processing run-time.

13 A new Time design time (input instance to the synthesizer) generate time (output proxy code to a file) compile time (compile the new proxy) Linking time (dynamically link to the proxy and classes it uses) Run time (where invoke method in the proxy)

14 Why do semi-automatic static proxy delegation? Better interface to a complex system Better Code Reuse Easier than manual message forwarding Type safe Easier maintenance Alternative to inheritance

15 What is wrong with using Multiple Inheritance? No MI in Java! Less reliable –duplicate methods with the same signature then you must disambiguate –shadowing is decided at compile-time using some technique –topological sorting is an automatic means of disambiguating.

16 Example of MI Confusion class TrigRad { public double cos(double d) { return Math.cos(d);//in radians }

17 TrigDeg class TrigDeg { public double cos(double d) { return Math.cos(d * Math.PI/180.0); }

18 MI and Trig class Confusion extends TrigRad, TrigDeg { double d = cos(90); }// this is not allowed in Java but is // in C++ or Smalltalk. Or in ZetaLisp // Simula Ambiguity can exist for topological sorting in MI.

19 What is Diamond Inheritance? base class is sub-classed by two other classes that are in turn sub-classed by a 4 th class. Stream IS OS IOS

20 What is wrong with Diamond Inheritance? Has all the problems of multiple inheritance. More complex for linking stage. Overhead for each instance grows. Most of the overhead is in malloc or NEW memory is taken from the HEAP. Fragile base class (constant recompilation)

21 What is good about Diamond Inheritance? Automatic addition of features to a subclass. Single large class. Toolkits are easier to create

Download ppt "Message Forwarding Semi-automatic proxy delegation."

Similar presentations

Ads by Google