Reflex Elements in a Nutshell

In this section we will briefly review the most important elements of Reflex from the user's point of view. We will see what hooksets, metaobject definitions and behavioral links are. Besides we will review structural metaobjects and links. And Finally, a subsection to explain where to define these elements.

Hooksets

Hooksets describe the execution points of an application to which the aspect applies, ie, the where. In Reflex, possible execution points are operations present in the application: a message send, a field access, object creation among others.

Hooksets can match certain operations based on two things: the class characteristics where the operation occur and the operation characteristics. We review the Hookset API in detail here.

Metaobject definitions

Once we have defined where an aspect will apply through a hookset, we need to define _what_ to do at those points, which is described by metaobject definition. This descriptor tells Reflex what metaobject it should use. It is important to mention that any object can be used as a metaobject.

Reflex accepts several kinds of metaobject definitions (all subclasses of MODefinition, that is described in detail here).

To clarify this, let us briefly review four subclasses provided by Reflex:

  • SharedMO, a pre-existing (already instantiated) object will be used, for example: System.out or an object obtained from a framework.
  • MOClass, a new metaobject will be created when necessary (ie, when the metaobject is about to be used), based on the description given to the MOClass object.
  • SharedFactory, a pre-existent factory of metaobjects will be used. This factory will be asked for every metaobject that is about to be used.
  • FactoryClass, a new factory (meaning Reflex will create one when necessary) of metaobjects will be used. This factory will be asked for every metaobject that is about to be used and that has not been initialized yet.

A BLink (behavioral link) can be seen as an object that acts as a relation between the hookset and the metaobject. This object provides several properties that describes how the communication will be done (there are others properties related to performance, cardinality of the relation, etc).

Once you have the hookset and the metaobject definition, the creation of behavioral links is very easy:

BLink blink = API.links().createBLink(hookset, moDefinition);

From a behavioral link, you can obtain a reference to a runtime link: a runtime representation of the behavioral link, which has several methods to alter the properties of a link such as the associated metaobject and the activation value.

The API of behavioral links is described in detail here. Whereas the API of runtime links, here.

Structural links and structural metaobjects are used to alter the structure of a class (like behavioral links and metaobjects are used to alter the behavior defined by a class).

Structural metaobjects must implement the SMetaobject interface and its unique method handle(RClass), where the modifications to the class must be done.

Structural links are the relation between the class and the structural metaobject.

In Reflex, the way to define links that will be available since the start of the application is to use a link provider. A link provider is an instance of a class that implements the ILinkProvider interface:

public interface ILinkProvider{
    public Collection<Link> getLinks();
}

As you can see, this interface defines only one method: getLinks, method that must return the links that the provider wants to contribute to the system.

In the following chapter we will see several examples that uses all these elements.