Section 11.4. SPECIFYING COMPOSITIONAL STYLES WITH FORMS


11.4. SPECIFYING COMPOSITIONAL STYLES WITH FORMS

We now briefly survey some of the typical compositional styles and techniques that are used to make software more flexible and adaptable. We demonstrate how Piccola forms support them. Note that these styles are not orthogonal.

Component algebras. A component algebra is a compositional style in which the composition of two or more components is again a component. The best-known example of a component algebra is pipes and filters. The components are sources, filters, and sinks, and the principle operator is the pipe. A source composed with a filter yields a source, and a filter composed with a filter is again a filter.

We believe that any compositional style can be conveniently expressed as a component algebra. In addition to pipes and filters, we have developed and experimented with component algebras for GUI components [6], input/output streams [4], coordination of concurrent agents [3], and mixin layers [21].

Higher-order wrappers. Many kinds of extensions can be factored out as simple wrappers, adding "before and after" behavior. Since all values (including abstractions) are forms in Piccola, abstractions are higher-order, making it easy to specify higher-order wrappers. As we have seen in Section 11.2.2, services in Piccola are monadic, always taking a single form as an argument. This makes it possible to define generic wrappers that do not depend on the number of arguments. Piccola uses wrappers heavily to adapt components to conform to a particular style.

Glue abstractions. Many glue abstractions can be expressed as simple wrappers. Glue abstractions can wrap known services or add new ones while leaving others undisturbed [16, 26]. A simple glue abstraction, for example, can wrap a java.math.BigInteger to provide it with the usual arithmetic operators. (Java does not provide operator overloading, so a Biginteger provides methods like add and multiply instead of + and *.)

Mixins and metaobjects. Higher-order wrappers make it possible to define mixins and other composition mechanisms for building objects. Piccola provides only forms as "primitive objects," but one can define a variety of other object models on top of forms [26]. One of Piccola's few keywords is def, used to define a fixpoint, but it is also possible to delay binding of self, which makes object models with explicit metaobjects attractive. Metaobjects enable run-time reflection [12].

Coordination abstractions. Piccola provides primitives to instantiate concurrent agents or to explicitly create new channels within scripts. The formal semantics of Piccola is in terms of a process calculus, so concurrency is built-in, not added on [16, 26]. This makes it easy to define coordination abstractions as abstractions over scripts. Furthermore, coordination can be seen as a special case of scripting, and many coordination styles can be naturally expressed as component algebras [3].

Implicit policies. Forms are also used in Piccola to represent namespaces [5]. Whenever a script is evaluated, it has access to two special namespaces, representing respectively the root context and the dynamic context. The root context defines the global environment, but can be specialized to define a "sandbox" for an untrusted agent or to override or extend global services (like println). The dynamic context is the environment provided by a client of an agent and can be used to define implicit policies. This mechanism can be used, for example, to define an exception handling mechanism for Piccola [5, 6] (the handler is always passed in the dynamic context). The same mechanisms are used more generally to optionally override any kind of default policy.

Default arguments. Since abstractions are monadic, taking a single form as an argument, and since forms can be extended, it is straightforward to define default arguments for services, as we did in defining the ** mixin layer composition operator.



Aspect-Oriented Software Development
Aspect-Oriented Software Development with Use Cases
ISBN: 0321268881
EAN: 2147483647
Year: 2003
Pages: 307

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net