Automating Crosscutting Modification

22
Automating Crosscutting Automating Crosscutting Modification Modification By Michael Kleyman

description

Automating Crosscutting Modification. By Michael Kleyman. When AOP is Used?. It is usually said that aspects represent crosscutting concerns. No clear definition of such a concern. AOP can be dangerous when overused. Trivial Examples. Logging Authorization. Telecom Example. - PowerPoint PPT Presentation

Transcript of Automating Crosscutting Modification

Page 1: Automating Crosscutting Modification

Automating Crosscutting Automating Crosscutting ModificationModification

By Michael Kleyman

Page 2: Automating Crosscutting Modification

When AOP is Used?When AOP is Used?

It is usually said that aspects represent crosscutting concerns.

No clear definition of such a concern.AOP can be dangerous when overused.

Page 3: Automating Crosscutting Modification

Trivial ExamplesTrivial Examples

LoggingAuthorization

Page 4: Automating Crosscutting Modification

Telecom ExampleTelecom Example

Calls, messaging etc. are the core conceptsRepresented by classes, such as Call or Connection

Billing is the crosscutting concern, represented by an aspect.

Payment calculation initiated in advices to methods of the core classes.

Page 5: Automating Crosscutting Modification

When AOP is helpful, but not When AOP is helpful, but not usedused

Corporate policies do not allow use of experimental, immature technologies

An aspect allows rapid modification of existing code, but the resulting program structure is not the best possible structure

Crosscutting modification as opposed to crosscutting concern

Page 6: Automating Crosscutting Modification

Example: Object PoolingExample: Object Pooling

Goal: reuse objects instead of creating new ones

Can be represented by a factory class.Introducing object pooling into existing

system is difficult.AspectJ allows an easy but controversial

solution

Page 7: Automating Crosscutting Modification

What is ACMEWhat is ACME

Convert AspectJ solution to pure JavaProve of conceptBased on specific examplesAdditional examples may be covered later

Page 8: Automating Crosscutting Modification

Key GoalsKey Goals

Java code must produce exactly the same results as the aspect code.

Java code should not be significantly longer than the aspect code.

The produced code should be easily modified and used.

Page 9: Automating Crosscutting Modification

Key Goals (Continued)Key Goals (Continued)

The generated code must look similar to code written by a human programmer.

Based on commonly used patterns and idioms.

Page 10: Automating Crosscutting Modification

ACME vs. AspectJ CompilerACME vs. AspectJ Compiler

Must not support the entire languageMust generate meaningful names (possibly

with user’s help)May not use some complicated structures

used in the compiler.

Page 11: Automating Crosscutting Modification

Workflow with ACMEWorkflow with ACME

Implement the required modification using aspects

Test the implementationWhen the result is satisfactory, run ACME

to generate pure Java code with same functionality

Page 12: Automating Crosscutting Modification

Creating Singleton ClassCreating Singleton Class

Aspect interacts with other code through pointcuts on functions of a single class.

Aspect is converted to a class automatically.All calls that are advised by the aspect are

replaced by calls to the singleton.Example: object pooling.

Page 13: Automating Crosscutting Modification

Inlining Aspect CodeInlining Aspect Code

Aspect may be used to modify both interface and behavior of an existing class.

Involves both advises and inter-type member declarations.

Example: modification of the Point class.Example: introduction of transactions

Page 14: Automating Crosscutting Modification

Automatic ModificationAutomatic Modification

Add the member introduced by the inter-type declaration to the class

Add a function for each adviceReplace all calls advised by the aspect by

calls to the new functions

Page 15: Automating Crosscutting Modification

Aspect HierarchiesAspect Hierarchies

Allow code reuse in several aspectsTypically involve abstract pointcuts and

concrete implementation of the advicesTransformed into hierarchies of classes

where the leaves are implemented as singletons.

Page 16: Automating Crosscutting Modification

When ACME helps?When ACME helps?

Evolution aid: test before changing the system.

RefactoringEases adoption of aspect technology

Page 17: Automating Crosscutting Modification

When not?When not?

Aspect represent crosscutting concernsAspects used as a configuration tool for

different application of the system

Page 18: Automating Crosscutting Modification

Unsupported Language Unsupported Language FeaturesFeatures

WildcardsType-dependent pointcut definitionsImplicit type castingCompile-time applications of aspects, such

as “declare error”Execution pointcuts

Page 19: Automating Crosscutting Modification

More on More on executionexecution join points join points

Require replacing the implementation of functions, not the calls to them.

With inheritance require replacing several functions for each advice.

Anything but the simplest around advice must be transformed to very complicated code

Very limited benefit

Page 20: Automating Crosscutting Modification

Case StudyCase Study

ACME was applied to Shay Raz’s work on system scaling with aspects.

Some aspects required cosmetic changes before processing.

Some can not be processed because they involve implicit type casting.

Possible solution: rewrite the aspects, removing abstract pointcuts from the base aspect.

Page 21: Automating Crosscutting Modification

Implementation DetailsImplementation Details

Built as an Eclipse pluginUses JDT library for Java source

manipulationThere is no such library for AspectJ code

Page 22: Automating Crosscutting Modification

Algorithm StepsAlgorithm Steps

Parse the AspectJ filesCreate new classes for “singleton” aspects.Add new members to existing classesFind advised function calls (using JDT)Replace these calls by calls to generated

functions