Implemented by Predrag Petkovic using ReflectionBeans
The name Demeter refers to the Law of Demeter (LoD), and its application to adaptive programming. The Law of Demeter was originally formulated as a style rule for designing object-oriented systems. ``Talk only to your immediate friends '' was the motto. In the more general formulation of the Law of Demeter, each unit is permitted access to a set of other units, but this set is limited to only closely related units. The revised motto is: "talk to friends; don't talk to strangers. "
The main motivation for the Law of Demeter is to help control information overload. It is rooted in the observation that we can only keep a limited set of items in short-term memory. The definition of closely related is intentionally left vague, so that the rule can be adapted to particular circumstances. In the application of the Law of Demeter to object-oriented design and programming, units are methods, and closely related methods means methods defined in three groups of classes: the type of the receiver, the types of formal arguments of the methods, and the return type classes.
This work deals with the application of the Law of Demeter also to components. The term Beans is borrowed from Sun Microsystems: JavaBeans are the Java programming language's components. Beans, beyond objects, permit also introspection . Following the Law of Demeter of talking only to your friends, beans take a step further and permit clients to "first ask your friends what they wish to talk about. "
DemeterBeans is the code-name for an extended JavaBeans API that is being developed at Northeastern University for supporting an adaptive introspector. Introspection is the ability of bean-builder tools to learn about the properties, events and methods provided by a third-party bean. The introspector (java.beans.Introspector) helps obtaining this information by using both reflective information (java.lang.reflect) and the bean provided BeanInfo class, which provides additional information about the bean.
Typically bean-builder tools use introspection to access only immediate features of a class. There is no ability to find, e.g., deeply nested attributes. For example, if the bean has a property of Font, and Font has a property Style, then we are not able to directly set the style of the bean's text. DemeterBeans gives you that additional capability. This is particularly useful with the JDK 1.2 Containment and Services Protocol.
DemeterBeans work by building the class graph for a set of JavaBeans components in the program. The class graph is then used to lift methods deeply inside a class to the interface of the class. An extended BeanInfo class that exposes this information to clients is generated in an adaptive manner. The process applies the idea of strategies (succinct navigation specifications) to the problem of navigating through the methods of an API. The benefit is that a high level API can be defined without hard-wiring the details of the low-level API into the implementation of the high-level API. This makes it easier to maintain high-level APIs in the presence of sifting low-level APIs.
Some of the challenges involved in this project are the following issues. Ensuring the invocation of lifted methods on the right objects. Setting the responsibilities of lifting. Setting the time the lifting is done (e.g., at composition time we can lift only what we need in a structure-shy way); and generalizing the idea of DemeterBeans beyond JavaBeans, i.e., applying DemeterBeans to other kinds of object-oriented components (e.g., aspectual components ).
Joint research with
KARL LIEBERHERR,
College of Computer Science,
Northeastern University,
Boston, Massachusetts 02115-5000.
Email: {lorenz,lieber}@ccs.neu.edu
David H. Lorenz
College of Computer Science,
Northeastern University,
Boston, Massachusetts 02115-5000.
Email: lorenz@ccs.neu.edu