[aspectc-user] New to AOP !!

Sanjay Dahiya, Noida sanjay at noida.hcltech.com
Tue Apr 23 09:06:38 CEST 2002


Hi -

I am new to the AOP world and intend to work in this field as I find it very
interesting. Lately I have studying 
AOP for Java and for C++ both. There are things that I would like to share
and get views on. 
Please correct me if I am wrong anywhere.

One fundamental idea behind AOP is to write find patterns in the code
(Joinpoints) and write generic code which 
could execute at those joinpoints.

The AOP language and the approach at some points seems to be restrictive in
looking for the patterns. There are many logical patterns in a software that
one is able to otherwise realize but not detect and operate upon
programmatically using AOP. 

					
			'context in this case can be read as a method.'
Example, I want to check for all pointer variables that are created in local
or class scope Before such a variable is accessed for the first time in a
context I want to check if it is null. If it is so I wish to throw an
exception.

Similarly if I want to delete all Local pointer variables declared and
allocated in a context after they have been referred for the last time in
the same context.

Or say I want to throw and propagate any exception to the interface/API
methods which are identified by a 
nomenclature specific to my product or organization.

These requirements give remind of prolog-like languages where you can pass
the results of one expression/rule
into another and filter the results like this.

Another similarity I realize is of rule based systems, One philosophy behind
a rule based system is that the code 
is not the software. It the [code + set of rules about how to use that code]
combination what make and governs 
how to a software. But rule based approach is presently more inclined
towards configuring the code for business functionality.
While working on rule based systems I found some useful applications for AOP
(Java in this case). but here I feel 
AOP could also use some concepts from rule based approach.

What I feel is that a mix of approaches here would be of more use, It should
be the [code + set of rules ] about 
the code which decide how to make a program from a code base. It could be
how to create/use/destroy the variables, how and whether to throw exceptions
and in many cases governing the flow of control of the program.

To achieve such a level of flexibility, a prolog-like language for defining
rules on the code base to generate a program could be thought of, which can
provide users with some well-defined patterns and ability to create new
patterns. A mix of this with well-defined nomenclature for an organization
or a project can lead to real maintainable and extensible products.

For this one more thing that has to be there is variable binding, One should
be able to bind the results of executing one rule which could be methods,
class or code points (I guess using XML would be a good choice internally
for implementing such a system) to a variable and pass it on to the next
rule/expression (something similar to prolog).

For example if I define following constructs or in-built patterns and allow
variable binding then problem of freeing the unused memory can be taken as:
Note: The syntax and constructs might not be very viable or valid but they
are just to convey the idea.

1. createdInContext:  
			The variable is created in the specified context.
refers to the creation point or 
			joinpoint of the variable.
2. allocInContext:
			The variable essentially a pointer variable is
allocated memory in this context, using 
			'new'.
			Assuming all memory is created or deleted using new
only.
3. lastRefInContext:
			The pointcut refers to a point where last reference
is made to this variable in the 
			supplied context.
4. firstRefInContext:
			The pointcut refers to a point where first reference
is made to this variable in the 
			supplied context.
5. exitPointOfContext: 
			This pointcut refers to the exit points including
end, all returns, throws from this 
			method.


	
----------------------------------------------------------------------------
-------
	pointcut lastPtrReference (x, co) = 	c = void
FigureElement::setXY(int, int) &&	
							// identify the
context in which to operate
						setCurrentContext(c),
							// a method of AOP
system
						(x = p%) && 
							// all pointer
variables available in this 
							// scope/context
						createdInContext(x , c)  &&
							// All variables
which are created in this 
							// scope/context
						co = ExitPointOfContext(c);
							// return a code
point to act upon
	or for all methods
	pointcut lastPtrReference (x, co) = 	c = % %::%(..) &&
							// context for this
operation is all method calls
						setCurrentContext(c),
							// a method of AOP
system
						(x = p%) && 
							// all pointer
variables available in this 
							// scope/context
						createdInContext(x , c)  &&

							// All variables
which are created in this 
							// scope/context
						co = lastRefInContext(x ,
c);
							// return a code
point to act upon
	

	advice lastReference(x, co) : void after(co)
	{
		if(NULL != x)
		{
			delete x;
			x = NULL;
		}	
	} 
	
----------------------------------------------------------------------------
-------

regards
Sanjay



More information about the aspectc-user mailing list