21
Aspect-Oriented Aspect-Oriented Solutions to Solutions to Feature Feature Interaction Interaction Concerns Concerns Lynne Blair, Jianxiong Lynne Blair, Jianxiong Pang Pang Lancaster University, Lancaster University, U.K. U.K.

Aspect-Oriented Solutions to Feature Interaction Concerns Lynne Blair, Jianxiong Pang Lancaster University, U.K

Embed Size (px)

Citation preview

Page 1: Aspect-Oriented Solutions to Feature Interaction Concerns Lynne Blair, Jianxiong Pang Lancaster University, U.K

Aspect-Oriented Aspect-Oriented Solutions to Solutions to

Feature Interaction Feature Interaction ConcernsConcerns

Lynne Blair, Jianxiong Lynne Blair, Jianxiong PangPang

Lancaster University, U.K.Lancaster University, U.K.

Page 2: Aspect-Oriented Solutions to Feature Interaction Concerns Lynne Blair, Jianxiong Pang Lancaster University, U.K

In a nutshell …In a nutshell …

A two-level architecture for feature A two-level architecture for feature driven software developmentdriven software development One level, the One level, the base layerbase layer, for a feature’s , for a feature’s

core behaviourcore behaviour Object-oriented, e.g. JavaObject-oriented, e.g. Java

Another level, the Another level, the meta-layermeta-layer, for , for resolution modules to provide solutions resolution modules to provide solutions (resolutions) to feature interaction (resolutions) to feature interaction problemsproblems Aspect-oriented, e.g. AspectJ, AspectWerkz, etc.Aspect-oriented, e.g. AspectJ, AspectWerkz, etc.

Page 3: Aspect-Oriented Solutions to Feature Interaction Concerns Lynne Blair, Jianxiong Pang Lancaster University, U.K

Overview: Overview: Aspect-Oriented Aspect-Oriented ProgrammingProgramming

Range of techniques to facilitate Range of techniques to facilitate enhanced separation of concernsenhanced separation of concerns Historical links with reflective techniquesHistorical links with reflective techniques Also links with subject oriented programming, Also links with subject oriented programming,

composition filters, hyperslices, composition filters, hyperslices, superimpositions, etc.superimpositions, etc.

Recognises Recognises crosscutting concernscrosscutting concerns Security, logging, tracing, debugging, error Security, logging, tracing, debugging, error

handling, non-functional concerns, etc.handling, non-functional concerns, etc. AOP elegantly captures concerns that cut AOP elegantly captures concerns that cut

across modules and avoids “code-tangling”across modules and avoids “code-tangling”

Page 4: Aspect-Oriented Solutions to Feature Interaction Concerns Lynne Blair, Jianxiong Pang Lancaster University, U.K

A simple AOP tracing A simple AOP tracing exampleexample

Using AspectJ (Kiczales et al) – Using AspectJ (Kiczales et al) – http://aspectj.orghttp://aspectj.org a mature and well-supported AOP languagea mature and well-supported AOP language

aspect TraceAspect { // set up pointcut to trace all methods in all (base-level) classes pointcut allMethods(): execution(* *(..));

// around - describe what happens around the allMethods pointcut void around (): allMethods() { System.out.println(“Entering "+thisJoinPointStaticPart.getSignature()); proceed(); System.out.println("Leaving "+thisJoinPointStaticPart.getSignature());} }

Page 5: Aspect-Oriented Solutions to Feature Interaction Concerns Lynne Blair, Jianxiong Pang Lancaster University, U.K

Using Using AspectJAspectJ

Without aspects …

… with aspects

Page 6: Aspect-Oriented Solutions to Feature Interaction Concerns Lynne Blair, Jianxiong Pang Lancaster University, U.K

Applying AOP to Feature Applying AOP to Feature Driven DevelopmentDriven Development

Requirement: features must be capable Requirement: features must be capable of working with other featuresof working with other features

but, a feature designer cannot foresee future but, a feature designer cannot foresee future features that will interact with his/her featurefeatures that will interact with his/her feature

adding multiple instances of resolution code to adding multiple instances of resolution code to existing code compromises structure/ eleganceexisting code compromises structure/ elegance

this is a classic example of “code tangling”this is a classic example of “code tangling”

One solution: separate all resolution code One solution: separate all resolution code from core code using AOP techniquesfrom core code using AOP techniques

Result: a two-level architecture for FDDResult: a two-level architecture for FDD

Page 7: Aspect-Oriented Solutions to Feature Interaction Concerns Lynne Blair, Jianxiong Pang Lancaster University, U.K

A classic resolution A classic resolution example …example …

Consider standard telephony featuresConsider standard telephony features Classic interaction example: CFB vs VoiceMailClassic interaction example: CFB vs VoiceMail Implement CFB and VoiceMail as separate Implement CFB and VoiceMail as separate

featuresfeatures Simple resolution strategy:Simple resolution strategy:

Can viewed as logically belonging alone, Can viewed as logically belonging alone, rather than being embedded with CFB and/ or rather than being embedded with CFB and/ or VoiceMailVoiceMail

if BUSY and caller in <special_user_list>if BUSY and caller in <special_user_list> proceed with CFBproceed with CFBelseelse proceed with VoiceMailproceed with VoiceMail

Page 8: Aspect-Oriented Solutions to Feature Interaction Concerns Lynne Blair, Jianxiong Pang Lancaster University, U.K

Interactions and Interactions and resolutions in an email resolutions in an email

systemsystem Our study is based on the 10 email features Our study is based on the 10 email features

(and 26 identified feature interactions) from:(and 26 identified feature interactions) from: R. Hall, “Feature Interactions in Electronic R. Hall, “Feature Interactions in Electronic

Mail”, Feature Interactions in Mail”, Feature Interactions in Telecommunications and Software Systems VI Telecommunications and Software Systems VI (Glasgow), pp 67-82, 2000 (Glasgow), pp 67-82, 2000

Examples of features:Examples of features: RemailMessage – provides pseudonym for senderRemailMessage – provides pseudonym for sender AutoResponder – automatically replies to AutoResponder – automatically replies to

messagesmessages etc.etc.

Page 9: Aspect-Oriented Solutions to Feature Interaction Concerns Lynne Blair, Jianxiong Pang Lancaster University, U.K

Feature Interaction: Feature Interaction: Remailer vs AutoResponderRemailer vs AutoResponder

Interaction identified in Hall’s paper between Interaction identified in Hall’s paper between these 2 features - under 2 separate scenariosthese 2 features - under 2 separate scenarios

One interaction scenario:One interaction scenario: Bob has a Bob has a RemailRemail account and account and AutoResponderAutoResponder

feature. feature. Alice sends message to Bob’s Alice sends message to Bob’s RemailRemail account account

(pseudonym). (pseudonym). AutoResponderAutoResponder receives message via receives message via RemailMessageRemailMessage and replies automatically and and replies automatically and directly to Alice, using Bob’s real ID. directly to Alice, using Bob’s real ID.

Because Because AutoResponderAutoResponder replies directly, Alice replies directly, Alice infers the infers the RemailRemail account is Bob’s, thus defeating account is Bob’s, thus defeating RemailMessage’sRemailMessage’s purpose. purpose.

AliceBob’s

RemailerBob’s

AutoResponder

Page 10: Aspect-Oriented Solutions to Feature Interaction Concerns Lynne Blair, Jianxiong Pang Lancaster University, U.K

Resolution forResolution for Remailer vs Remailer vs

AutoResponderAutoResponder Resolution can be achieved by (at Resolution can be achieved by (at

least) two different mechanisms:least) two different mechanisms:1.1. In In AutoResponderAutoResponder, check if answering , check if answering

a message from the Remailer. If so, a message from the Remailer. If so, reply using the Remailing rule: reply using the Remailing rule:

2.2. OR, modify the Remailer to ensure OR, modify the Remailer to ensure that all replies pass back through it that all replies pass back through it (allocate sender a pseudonym)(allocate sender a pseudonym)

AliceBob’s

RemailerBob’s

AutoResponder

a) Send reply to Remailer with intended recipient as 1st line

b) Remailer re-routes reply having anonymised sender

Page 11: Aspect-Oriented Solutions to Feature Interaction Concerns Lynne Blair, Jianxiong Pang Lancaster University, U.K

Resolution (1) in AspectJResolution (1) in AspectJ

aspect SoftenAutoResponderForRemailer {

before(Message msg):execution(void AutoResponder.send(Message)) && args(msg) { //if msg is from Remailer, then respond to Remailer using the remailing rule if (isFromRemail(msg)) { writeContentFirstLine(msg.getReceiver()); msg.setReceiver(getRemailAddress(msg)); }} boolean isFromRemail(Message msg) { //check if msg is from Remailer ... } void writeContentFirstLine(String str) { //write intended recipient’s address in the 1st line of message content ... } String getRemailAddress(Message msg) { //get Remail Server’s address from msg ...}}

Page 12: Aspect-Oriented Solutions to Feature Interaction Concerns Lynne Blair, Jianxiong Pang Lancaster University, U.K

Summary so farSummary so far We have separated interaction resolution We have separated interaction resolution

modules from a feature’s core behaviour:modules from a feature’s core behaviour: Can Can introduceintroduce new methods and/or new new methods and/or new

attributes into feature’s behaviour as requiredattributes into feature’s behaviour as required Relatively easy to maintain separation w/out aspectsRelatively easy to maintain separation w/out aspects

Can weave new behaviour (advice) Can weave new behaviour (advice) aroundaround, , beforebefore or or afterafter existing feature behaviour existing feature behaviour

Difficult to maintain separation w/out aspectsDifficult to maintain separation w/out aspects Pointcuts can be defined over any execution Pointcuts can be defined over any execution

points in any feature boxpoints in any feature box i.e. aspects need not be specific to one feature boxi.e. aspects need not be specific to one feature box

Page 13: Aspect-Oriented Solutions to Feature Interaction Concerns Lynne Blair, Jianxiong Pang Lancaster University, U.K

EvaluationEvaluation To evaluate:To evaluate:

Extended system to all 10 features of R. Hall’s Extended system to all 10 features of R. Hall’s paperpaper

To create running system, refactored some of To create running system, refactored some of GUI modules from ICEMail (email client, Java GUI modules from ICEMail (email client, Java Mail API)Mail API)

Evaluation categories:Evaluation categories: Cleanness of separationCleanness of separation Re-useRe-use Faithfulness of implementation to specificationFaithfulness of implementation to specification Adaptability to requirement changeAdaptability to requirement change Support for interaction avoidance, detection, Support for interaction avoidance, detection,

and resolutionand resolution

Page 14: Aspect-Oriented Solutions to Feature Interaction Concerns Lynne Blair, Jianxiong Pang Lancaster University, U.K

Cleanness of separationCleanness of separation Object-orientation provides a widely accepted Object-orientation provides a widely accepted

and largely effective level of separationand largely effective level of separation Yet feature-oriented systems that require Yet feature-oriented systems that require

resolution modules for inter-working suffer resolution modules for inter-working suffer “code-tangling”“code-tangling”

Two-level architecture provides elegant Two-level architecture provides elegant separationseparation

Increasingly important as number of features ↑Increasingly important as number of features ↑ R. Hall’s paper - 10 features, 26 identified interactionsR. Hall’s paper - 10 features, 26 identified interactions Each interaction requires a resolutionEach interaction requires a resolution Possible interaction resolution Possible interaction resolution patternspatterns ICEMail system – “core” functionality: 800 lines → 70ICEMail system – “core” functionality: 800 lines → 70

Page 15: Aspect-Oriented Solutions to Feature Interaction Concerns Lynne Blair, Jianxiong Pang Lancaster University, U.K

Re-useRe-use

The cleanness of the “core” functionality, The cleanness of the “core” functionality, gives good opportunities for re-use (e.g. gives good opportunities for re-use (e.g. ICEMail)ICEMail)

Many resolution modules are very specific, Many resolution modules are very specific, hence only offer limited scope for re-usehence only offer limited scope for re-use

Re: patterns …Re: patterns … All of the 26 interactions arise from the need All of the 26 interactions arise from the need

for some level of boundary checkingfor some level of boundary checking Approx. half could be classed as ‘generic’ Approx. half could be classed as ‘generic’

(could be implemented as a pattern and (could be implemented as a pattern and applied elsewhere)applied elsewhere)

Still requires more work !Still requires more work !

Page 16: Aspect-Oriented Solutions to Feature Interaction Concerns Lynne Blair, Jianxiong Pang Lancaster University, U.K

Faithfulness of Faithfulness of implementationimplementationto specificationto specification

We claim that our two level We claim that our two level architecture:architecture: Improves readability and simplicity of Improves readability and simplicity of

codecode Allows a feature’s specification to map Allows a feature’s specification to map

more directly to its implementationmore directly to its implementation This, in turn, opens the door to This, in turn, opens the door to

generative programming techniques (for generative programming techniques (for code or code templates)code or code templates)

Page 17: Aspect-Oriented Solutions to Feature Interaction Concerns Lynne Blair, Jianxiong Pang Lancaster University, U.K

Adaptability toAdaptability torequirement changerequirement change

New features can be added to system New features can be added to system without consideration (or re-writing) of without consideration (or re-writing) of other featuresother features

Also no need to consider interactions Also no need to consider interactions when writing a feature – can focus on when writing a feature – can focus on these separatelythese separately

Similarly removal of features is Similarly removal of features is straightforwardstraightforward Avoids redundant code being left embedded Avoids redundant code being left embedded

with featureswith features

Page 18: Aspect-Oriented Solutions to Feature Interaction Concerns Lynne Blair, Jianxiong Pang Lancaster University, U.K

Support for interaction Support for interaction avoidance, detection and avoidance, detection and

resolution resolution This category in fact raised further questions …This category in fact raised further questions … Obvious problem:Obvious problem:

Resolution modules (aspects) can themselves interact Resolution modules (aspects) can themselves interact Many reflective architectures are multi-levelMany reflective architectures are multi-level

Should we relax 2-level architecture?Should we relax 2-level architecture? Meta-meta level is for solving resolution interactions?Meta-meta level is for solving resolution interactions?

Language choice – AspectJ?Language choice – AspectJ? Aspects of aspects not permittedAspects of aspects not permitted Composition is implicit - in other languages it’s Composition is implicit - in other languages it’s

explicitexplicit

Page 19: Aspect-Oriented Solutions to Feature Interaction Concerns Lynne Blair, Jianxiong Pang Lancaster University, U.K

Support for aspect Support for aspect interactions?interactions?

Avoidance – by ‘design by contract’ approach Avoidance – by ‘design by contract’ approach or explicit (restrictive) composition operatorsor explicit (restrictive) composition operators

Introduce meta-meta layerIntroduce meta-meta layer Formal techniques (cf. FIW) e.g. model-Formal techniques (cf. FIW) e.g. model-

checking properties of aspects (but which checking properties of aspects (but which properties?)properties?)

Aspect community’s work:Aspect community’s work: A framework for the detection & resolution of A framework for the detection & resolution of

aspect interactions, Douence, Fradet & Saspect interactions, Douence, Fradet & Süüdholt, dholt, GPCE’02GPCE’02

Superimpositions and aspect-oriented Superimpositions and aspect-oriented programming, Sihman, Katz, BCS Computer programming, Sihman, Katz, BCS Computer Journal 2003.Journal 2003.

Page 20: Aspect-Oriented Solutions to Feature Interaction Concerns Lynne Blair, Jianxiong Pang Lancaster University, U.K

Performance?Performance?

Coming soon!Coming soon! See FAQ on http://aspectj.orgSee FAQ on http://aspectj.org

Page 21: Aspect-Oriented Solutions to Feature Interaction Concerns Lynne Blair, Jianxiong Pang Lancaster University, U.K

Final commentFinal comment

Aspect-oriented approaches provide Aspect-oriented approaches provide powerful language-level support for powerful language-level support for resolution modulesresolution modules

Can be used to enhance traditional Can be used to enhance traditional software development practicessoftware development practices

This is This is notnot domain specific – examples domain specific – examples from:from: Telephony and emailTelephony and email Middleware’s system/ technical servicesMiddleware’s system/ technical services Tracking systemsTracking systems Building Control Systems (coming next) …Building Control Systems (coming next) …