Aspect-Oriented Programming

What is Aspect-orientation?

The objective of aspect-oriented (AO) languages is to improve a software engineer's ability to separate conceptual concerns. The problem that they address is that all dimensions of design decisions, or concerns, are not amenable to modularization by a single dimension of decomposition. Instead, some concerns cut across the dominant dimension of decomposition. These languages aim to improve the separation of these types of concerns thereby enhancing modularity.

In AO languages such as AspectJevents (called ``join points'') are pre-defined by the language as certain kinds of standard actions (such as method calls) in a program's execution. AO events are all implicitly announced. Pointcut descriptions (PCDs) are used to declaratively register handlers (called "advice") with sets of events. Using PCDs to register a handler with an entire set of events, called quantification, is a key idea in AO languages that has no counterpart in II languages. A language's set of PCDs and its set of events form its event model (in AO terms this is a "join point model").

An Example of Aspect-orientation

As an example, consider a drawing editor which consists of objects such as Points, Lines, etc. Each element is part of the overall figure and extends the FElement class. Other classes may be interested in knowing when such figure elements change. For example, there may be an Update class that updates the figure on the screen when any element changes.

	public interface FElement {
	}

The class Point is an example of an FElement. Points have an x and a y location and setter methods setX and setY. Points also have a method makeEqual, which will set the x and y location of its argument to that of the current instance.

	public class Point implements FElement {
		int x;
		int y;
		public void setX(int x) {
			this.x = x;
		}
		public void setY(int y) {
			this.y = y;
		}
		public void makeEqual(Point other) {
			other.x = this.x;
			other.y = this.y;
		}
	}

Finally consider the Update aspect, which is responsible for updating the figure elements on the screen. The aspect states that after a call to any method in a FElement instance with a name starting with either set or makeEq, the display is updated.

	aspect Update {
		after() : call(FElement+.set*(..)) || call(FElement+.makeEq*(..)) {
			Display.update();
		}
	}

Limitations of Aspect-oriented Languages

AO languages have following three limitations, primarily because most current event models use lexical PCDs. Such PCDs use patterns of names; for example, call(set*(..)) describes a set of call events in which the name of the called method starts with set.

	after() : call(FElement+.set*(..)) || call(FElement+.makeEq*(..))
  • Lexical PCDs are fragile. Consider the PCD above, when the developer adds a method named "settled" to the Point class. The PCD will capture this point in the program's execution.

    	public void setX(int x) {
    		if (this.x != x)
    			this.x = x;
    	}
    
  • Lexical PCDs exhibit quantification failures. Consider the code above, which only sets the value of x if it is different.
  • Additionally, lexical PCDs make it unnecessarily hard to uniformly access information from an event's context.

Page last modified on $Date: 2011/07/29 10:45:47 $