Better Separation of Crosscutting Concerns with Aspectual Components - PowerPoint PPT Presentation

1 / 39
About This Presentation
Title:

Better Separation of Crosscutting Concerns with Aspectual Components

Description:

HashSet collect(ClassGraph cg, String constraint){ Visitor v = new Visitor ... middle() 'to Target', v); expected String middle() {return new String ... – PowerPoint PPT presentation

Number of Views:25
Avg rating:3.0/5.0
Slides: 40
Provided by: karllie
Learn more at: https://www2.ccs.neu.edu
Category:

less

Transcript and Presenter's Notes

Title: Better Separation of Crosscutting Concerns with Aspectual Components


1
Better Separation of Crosscutting Concerns
withAspectual Components
  • Karl Lieberherr
  • College of Computer Science
  • Demeter Group
  • Northeastern University, Boston

2
Overview
  • Aspect-Oriented Programming (AOP) Crosscutting
    concerns, controlling tangling and scattering.
  • Example Collect entities.
  • Tools for AOP
  • AspectJ from Xerox PARC
  • DJ from Northeastern
  • Adaptive Programming and AOP
  • Summary

3
The MIT Technology Review (Jan./Feb. 2001 issue)
  • Ten emerging technologies that will change the
    world
  • Untangling Code - Aspect-Oriented Programming
    (AOP)
  • Data Mining
  • Micro Fluids
  • Robot Design
  • ...

4
Northeastern Connection
  • Crista Lopes wrote the first Ph.D. Thesis on AOP
    at Northeastern supported by Xerox PARC. Gregor
    Kiczales co-advisor.
  • The Demeter Research Group worked with
    interesting AOP Systems long before the name AOP
    was invented.

5
Quote MIT Technology Magazine
  • The idea of aspects has been around for many
    years and with many different names. It is called
    adaptive programming at Northeastern University,
    and subject-oriented programming at IBM,

6
AOP not every concern fits into a component
crosscutting
Goal find new component structures that
encapsulate rich concerns
7
AOP
  • Crosscutting concerns
  • Example Logging record every operation an
    application performs
  • When adding a new operation to this application,
    always put a trace statement in
  • Keeping track of crosscutting concerns is
    error-prone

8
AOP
  • Crosscutting concerns, when implemented in an
    ad-hoc way, lead to a lot of tangling and
    scattering in the program.
  • Goal of AOP is to control the tangling and
    scattering in the program.

9
Tangling count color changes
ordinary program
better program
structure-shy functionality
Component 1
structure
Component 2
synchronization
Component 3
10
Scattering count number of modules to which
color goes
ordinary program
better program
structure-shy functionality
M1
Component 1
structure
M2
Component 2
M3
synchronization
Component 3
11
Aspect-Oriented ProgrammingExample
  • Separating the following crosscutting concerns
  • Object Structure concern (JAXB, optional package
    for Java 2 platform, XML schema UML class graph)
  • Traversal-related concerns traverse a group of
    connected objects and execute code attached to
    nodes and edges of object graph (advice).
  • separate traversals and advice
  • Those two kinds of concerns appear frequently.

12
Crosscutting in Equation System
overall graph object structure green graph
traversal purple advice
usedThings from EquationSystem through
Expression to Variable
equations
esEquationSystem
elsEquation_List
new HashSet
i1Ident
lhs
e1Equation
v1Variable
Object graph
rhs
elsExpression_List
c1Compound
i2Ident
v2Variable
a1Add
add
i3Ident
v3Variable
add
13
What is a component?
  • any identifiable slice of behaviour that delivers
    a meaningful service, involving in general
    several participants,
  • used via well-defined interfaces,
  • formulated for an ideal ontology - the input
    (expected) interface
  • can be deployed into a concrete ontology,
  • is subject to composition by 3rd parties
    (black-box reuse)
  • is subject to refinement by 3rd parties
    (white-box reuse)

14
Aspectual Component
Class Graph
P1
P3
P2
Behavior Definition
P
P1
before / around
provided everything public

after
written to the CG similar to an OO
program is written to a concrete class graph

...
P3
enhancements before/after/around provided
...
before
after
15
Collect Things
definedThings
System

Thing

usedThings


Definition
Body
definedThings from System bypassing Body to
Thing usedThings from System through Body to
Thing
16
M1 Equation System
EquationSystem
equations
Equation_List
Ident

Variable
lhs
Equation
Numerical
rhs
Expression_List
Simple
args
Expression

op
Add
Compound
17
M1 Equation System
definedThings from EquationSystem bypassing
Expression to Variable
EquationSystem
equations
Equation_List
Ident

lhs
Equation
Variable
Numerical
rhs
Simple
args
Expression_List
Expression
S
T

op
Add
Compound
D
B
18
M1 Equation System
usedThings from EquationSystem through
Expression to Variable
EquationSystem
equations
Equation_List
Ident

lhs
Equation
Variable
Numerical
rhs
Simple
args
Expression_List
Expression
S
T

op
Add
Compound
D
B
19
Aspectual Collaboration
  • collaboration COLLECT
  • participant Source
  • expected static ClassGraph cg
  • public HashSet collect(String constraint)
  • String id from Target to
    edu.neu.ccs.demeter.Ident
  • Visitor v new Visitor()
  • HashSet return_val new HashSet()
  • void before(Thing v1)
  • return_val.add(cg.fetch(v1, id) )
  • public Object getReturnValue()return
    return_val
  • Source.cg.traverse(this,
  • from Source constraint to Target,
    v
  • participant Target

20
Adapter part
  • // EquationSystem class graph
  • attach COLLECT
  • EquationSystem Source with
  • provide Sourcecg with
  • EquationSystemcg
  • Variable Target

21
Java code
  • class System
  • String id from Thing to edu.neu.ccs.demeter.I
    dent
  • HashSet collect(ClassGraph cg, String
    constraint)
  • Visitor v new Visitor()
  • HashSet return_val new HashSet()
  • void before(Thing v1)
  • return_val.add(cg.fetch(v1, id) )
  • public Object getReturnValue()return
    return_val
  • cg.traverse(this,from Systemconstraintto
    Thing, v)
  • return (HashSet)v.getReturnValue()
  • HashSet defined(ClassGraph cg)
  • return (HashSet) this.collect(cg, bypassing
    Body )
  • HashSet used(ClassGraph cg)
  • return (HashSet) this.collect(cg, through
    Body )

green traversal black bold structure purple
advice red parameters
22
Ad-hoc Implementation oftraversal-related
concerns
  • Leads to lots of tangled and scattered code with
    numerous disadvantages
  • The question is not how to eliminate the tangling
    but how to reduce it
  • AOP is about tangling control of the
    implementation of crosscutting concerns
  • Crosscutting will always lead to some tangling at
    code level

23
Name map
Definition ClassDef Production
Equation
24
Need more than localizationof crosscutting
concerns
  • If we localize a crosscutting traversal-related
    concern in the standard way, we get a method that
    violates the Law of Demeter
  • In addition Use traversal strategies to
    eliminate accidental noise in class graph
  • Need AP to improve AOP

25
AspectJ (Xerox PARC)
  • A general aspect-oriented programming language
    for Java.
  • An aspect is like a class and may contain
    pointcut definitions defining a set of join
    points and advice saying what to do before, after
    or instead of the join points.

26
DJ (Northeastern)
  • Is a Java package that supports AOP for
    traversal-related concerns.
  • Connection to AspectJ both can be used
    simultaneously.
  • DJ provides an implementation of Adaptive
    Programming (AP).

27
Concepts needed(DJ classes)
  • ClassGraph
  • Strategy ( Java String traversal strategy)
  • Visitor

28
Adaptive Programming
Strategy
Bold names refer to DJ classes.
is use-case based abstraction of
ClassGraph
defines family of
Object
29
Adaptive Programming
Strategy
defines traversals of
Object
30
Adaptive Programming
Strategy
guides and informs
Visitor
31
AspectJ (Xerox) DJ (NEU)
  • Abstract pointcut
  • set of execution points
  • where to watch
  • Advice
  • what to do
  • Concrete pointcut
  • set notation using regular expressions
  • Abstract object slice
  • set of entry/exit points
  • where to go
  • Visitor
  • what to do
  • Actual object slice
  • traversal strategies

32
AOP AP
  • Program with aspects that correspond to the
    concerns of the programmer.
  • Relieve the programmer from the details of some
    concern.
  • Create robustness to changes in an aspect.
  • AP is about join point reduction.
  • Example structure-shyness

33
Benefits of Adaptive Programming
  • robustness to changes
  • shorter programs
  • design matches program,
  • more understandable code
  • partially automated evolution
  • keep all benefits of OO technology
  • improved productivity

Applicable to design and documentation of your
current systems.
34
Summary
  • AOP getting a lot of attention. Addresses an
    important problem how to program crosscutting
    concerns.
  • AP is about relieving the programmer from the
    details of a concern traditionally from the
    structural concern.

35
Collaboration with strategies
  • collaboration checkDef
  • role System
  • out repUndef()(uses getDefThings,
    checkDefined)
  • getDefThings()(uses definedThings)
  • checkDefined()(uses usedThings)
  • in definedThings
  • from System bypassing Body to Thing
  • in usedThings
  • from System through Body to Thing
  • role Body
  • role Thing
  • role Definition

36
Collaboration with strategies
  • simple collaboration COLLECT
  • participant Source
  • public HashSet collectVars(ClassGraph cg)
  • Visitor v new Visitor()
  • cg.traverse(this,from Source
  • middle() to Target, v)
  • expected String middle() return new
    String()
  • participant Target
  • participant ClassGraph

37
Collaboration with strategies
  • simple collaboration COLLECT
  • import dj.ClassGraph
  • participant Source
  • expected static ClassGraph cg
  • public String clname Source.class.getName()
  • public HashSet collectVars()
  • Visitor v new Visitor()
  • Source.cg.traverse(this,from
    Source.class.gteName()
  • middle() to Target.class, v)
  • expected String middle() return new
    String()
  • participant Target

38
Collaboration with strategies
  • composite collaboration ES
  • participant EquationSystem
  • static ClassGraph cg new ClassGraph(true,fals
    e)
  • attach COLLECT
  • EquationSystem Source with middle m
  • provide Sourcecg with Equationsystemcg
  • export collectVars
  • Variable Target
  • participant Source
  • expected static ClassGraph cg
  • public String clname Source.class.getName()
  • public HashSet collectVars()
  • Visitor v new Visitor()
  • cg.traverse(this,from
    Source.class.gteName()
  • middle() to Target.class, v)

39
Summary
  • We view components as slices of behavior
  • Aspectual components
  • reconcile between functional and object
    decomposition
  • both add new behavior and modify existing
  • are a good model for AOP
Write a Comment
User Comments (0)
About PowerShow.com