Proxy

The Proxy module provides a basic Proxy pattern through its ProxyService and service classes. The idea behind the proxy pattern is to provide a means of redirecting messages sent to objects that do not define the required property to service objects that do.

 

The ProxyService Model

A ProxyService object is a composite object composed of a parent object (the ProxyService object), components (service objects), and a pointer to a class that will handle any properties not handled by the ProxyService or one of the service objects.

 

 

The basic rules for redirection and delegation are:

 

  1. if the property is defined (directly or through inheritance) by the ProxyService object, then the ProxyService object should handle the property call.
  2. If the property is a &remapToXXXX property then we examine each service object in turn to see if it defines the &actionXXXX property for the action. If one and only one service object defines the &actionXXXX property then we remap the action to this object.
  3. If neither #1 nor #2 is satisfied then we delegate the property call to the default handler class.

 

Using Inner Classes to Define Services

We can use inner classes to make the ProxyService object definition more compact.

 

Suppose we want to create a desk that has a surface and an inside. We can do so compactly by defining it with nested objects for each of its components:

 

woodenDesk: ProxyService

{

    'wooden desk' 'wooden desk' @entryway

 

    proteusServiceFor(Service)

    {

        mySurface: Fixed, Surface

        {

            'desk surface' 'desk surface'

        }

        myContainer: Fixed, OpenableContainer

        {

            'desk drawer' 'desk drawer'

        }

    }

}

 

A sample transcript of what this simple definition can do follows:

 

Entryway

This large, formal entryway is slightly intimidating: the walls are lined with somber portraits of gray-haired men from decades past; a medieval suit of armor, posed with a battle axe at the ready, towers over a single straight-backed wooden chair. The front door leads back outside to the south. A hallway leads north.

 

You see a wooden desk here.

 

>put axe in desk

(first taking the battle axe)

(first opening the desk drawer)

Done.

 

>put axe on desk

(first taking the battle axe)

Done.

 

>close desk

Closed.

 

>l

Entryway

This large, formal entryway is slightly intimidating: the walls are lined with somber portraits of gray-haired men from decades past; a medieval suit of armor towers over a single straight-backed wooden chair. The front door leads back outside to the south. A hallway leads north.

 

You see a wooden desk here. On the desk surface is a battle axe.

 

 

This file is part of the TADS 3 Proteus Library Extension

Copyright © 2001-2004 Kevin Forchione. All rights reserved.