Forwarding - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Forwarding

Description:

... Prototype-based OO Languages. Forwarding in Compose* Final ... Resending is used for forwarding. 12 /19. 2006 Stephan Huttenhuis. Prototype-based OO languages ... – PowerPoint PPT presentation

Number of Views:76
Avg rating:3.0/5.0
Slides: 20
Provided by: Huttenh
Category:

less

Transcript and Presenter's Notes

Title: Forwarding


1
Forwarding
  • Stephan Huttenhuis
  • Februari 23, 2006

2
Contents
  • Forwarding in Patterns
  • The Self Problem
  • Different Types of Forwarding
  • Class- vs. Prototype-based OO Languages
  • Forwarding in Compose
  • Final Remarks

3
Forwarding in Patterns
  • Some design patterns make heavy use of forwarding

4
Forwarding
  • Allows adding new behaviour (strategy)
  • Allows changing behaviour at run-time (strategy).
  • The consequence is that a conceptual entity
    (strategy) is split among several classes (i.e.
    Context and a ConcreteStrategy).

5
Self Problem
  • Pseudo-variable Self (this in Java) is used to
    indicate the receiver of a request.
  • The receiver object (Context) forwards a message
    to another object (Strategy).
  • Self is rebound and it is no longer possible to
    access the original receiver through Self. This
    is known as the Self problem.

6
Self Problem example (1)
7
Self Problem example (2)
This points to the QuickSort object, but
should point to the Sorter object.
8
Self Problem Simulation
  • A workaround is to send the receiver object
    (Sorter) as an argument. This is called true
    delegation Gamma et al., 95.
  • It changes the sort method signature.
  • It reduces reusability because a specific type is
    passed or a cast is needed (in statically-typed
    languages).

9
Different types of forwarding
  • How is the Self-pseudo variable bound?
  • Bound to the object that receives a request.
  • What is the receiver depends on point of view.
  • How is the message forwarded?
  • Explicitly repeat method call
  • Automatically by defined parents
  • Supported by different language constructs

10
Different types of forwarding
  • From Günter Kniesel - Dynamic Object-Based
    Inheritance with Subtyping

E.g. A message sorter.sort() is send, it
is forwarded to strategy.sort()
11
Class-based OO languages
  • Most mainstream OO languages
  • Classes
  • Object creation by class instantiation
  • Behaviour sharing by inheritance
  • Object state sharing is difficult
  • Message passing for method invocation
  • Resending is used for forwarding

12
Prototype-based OO languages
  • Some OO languages like Self (http//research.sun.c
    om/self/)
  • Object creation by cloning
  • Object structure change
  • Behaviour and state sharing by delegation
  • Both behaviour and state are slots
  • Parent link
  • Message passing for method invocation
  • Delegation is used for forwarding

13
Resending
  • All methods must be defined on the interface of
    the original receiver.
  • Forward methods require a lot of work.
  • Cannot implement evolving object behavior i.e.
    need recompilation.
  • Self problem.
  • Conversion of method call is easy e.g. change
    method name

14
Delegation
  • No conversion of a method call without resorting
    to resending or explicit delegation.
  • Automatic forwarding
  • Enables a conceptual entity to be separated
    into multiple objects, while operating as a
    single object.

15
Delegation in Compose
  • Name Matching and Signature Matching
  • No Self-problem
  • The original receiver can be retrieved by
    MessageInfo.getMessageInfo().getServer(). But we
    need a cast to the actual type.
  • The method holder can be accessed by Self in the
    base language.

16
Name Matching
17
Signature matching
18
Name vs. Signature matching
  • Name matching
  • Similar to resending / explicit delegation
  • One forward definition per method selector (per
    condition)
  • Signature matching
  • Similar to consultation / automatic delegation
    (need cast)
  • One forward definition per parent object (per
    condition)
  • No need to implement forward methods
  • Associative delegation can improve condition
    situation

19
Final Remarks
  • Forwarding is used in several patterns.
  • Forwarding and delegation are often misleading
    terms.
  • Compose supports delegation. This is a benefit
    compared to Java and AspectJ.
  • Language constructs influences the pattern
    implementations.
Write a Comment
User Comments (0)
About PowerShow.com