Upload
yana
View
41
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Better Separation of Crosscutting Concerns with Aspectual Components. Karl Lieberherr College of Computer Science Demeter Team Northeastern University, Boston www.ccs.neu.edu/research/demeter. Team. with Professors Felleisen, Lorenz, Wand Ph.D. students: Doug Orleans, Johan Ovlinger - PowerPoint PPT Presentation
Citation preview
04/22/23 Aspectual Components 1
Better Separation of Crosscutting Concerns with
Aspectual Components
Karl LieberherrCollege of Computer Science
Demeter TeamNortheastern University, Boston
www.ccs.neu.edu/research/demeter
04/22/23 Aspectual Components 2
Team
• with Professors Felleisen, Lorenz, Wand• Ph.D. students:
– Doug Orleans,– Johan Ovlinger– Therapon Skotiniotis– Pengcheng Wu
04/22/23 Aspectual Components 3
Overview• Aspect-Oriented Programming (AOP):
Crosscutting concerns, controlling tangling and scattering.
• Example: Collect entities.• Aspectual Components + DJ• Comparison to AspectJ• Summary
04/22/23 Aspectual Components 4
Message
• AOP is useful and has a long history at NU• Aspectual components, an AOP
mechanism, are useful• Adaptive Programming mechanisms must
be used to properly express traversal-related aspects
04/22/23 Aspectual Components 5
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– ...
04/22/23 Aspectual Components 6
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.
04/22/23 Aspectual Components 7
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, …”
04/22/23 Aspectual Components 8
AOP: not every concern fits into a component: crosscutting
CM1 CM2 CM3 CM4 CM5 CM6
CR1 x
CR2 x
CR3 x
CR4 x x x xGoal: find new component structures that encapsulate “rich” concerns
04/22/23 Aspectual Components 9
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
04/22/23 Aspectual Components 10
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.
04/22/23 Aspectual Components 11
Tangling: count color changesordinary program
structure-shyfunctionality
structure
synchronization
better program
Component 1
Component 2
Component 3
04/22/23 Aspectual Components 12
Scattering: count number of components to which color goesordinary program
structure-shyfunctionality
structure
synchronization
better program
Concern 1
Concern 2
Concern 3
CM1
CM2
CM3
04/22/23 Aspectual Components 13
Aspect-Oriented Programming:Example
• 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.
04/22/23 Aspectual Components 14
Crosscutting in Equation Systemequations
lhs
rhs
es:EquationSystem els:Equation_List
e1:Equation v1:Variable
i1:Ident
v3:Variable i3:Ident
new HashSet
c1:Compoundels:Expression_List
a1:Addv2:Variable i2:Ident
add
add
usedThings = from EquationSystem through Expression to Variable
overall graph: object structure; green graph: traversal; purple: advice
Object graph
04/22/23 Aspectual Components 15
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 – 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)
written to the CG similar to an OO program is writtento a concrete class graph
expected interfaces
minimal assumptions on
application structure
+
P1
PP1
P3
...
meth3,1...
P2 P3
meth3,j
meth1,k
meth1,1
provided =
everything public
Aspectual Component
before / aroundafter
before / aroundafter
enhancements =
before/around/after+
provided
04/22/23 Aspectual Components 17
M1: Equation SystemEquationSystem
Equation_List
EquationVariable
equations
*lhs
rhs
ExpressionSimple
Compound
Numerical
Expression_List
* Addop
args
Ident
04/22/23 Aspectual Components 18
Collect Things
System
Body
Thing
* *
*definedThings
usedThings
definedThings = from System bypassing Body to ThingusedThings = from System through Body to Thing = from System + constraint + to Thing
*
Definition
04/22/23 Aspectual Components 19
M1: Equation SystemdefinedThings = from EquationSystem bypassing Expression to Variable
EquationSystem
Equation_List
Equation Variable
equations
*lhs
rhs
ExpressionSimple
Compound
Numerical
Expression_List* Addop
args
Ident
S
D
T
B
04/22/23 Aspectual Components 20
M1: Equation SystemusedThings = from EquationSystem through Expression to Variable
EquationSystem
Equation_List
Equation Variable
equations
*lhs
rhs
ExpressionSimple
Compound
Numerical
Expression_List*
Addop
args
Ident
S
D
T
B
04/22/23 Aspectual Components 21
Aspectual Componentcomponent 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 { }}
04/22/23 Aspectual Components 22
Aspectual Component
• Find appropriate class graph and traversals for task at hand
• Simplify from graph with 11 nodes to graph with 4 nodes to graph with two nodes.
04/22/23 Aspectual Components 23
Adapter part
// EquationSystem class graphattach COLLECT { EquationSystem += Source with { provide EquationSystem::cg to Source::cg; } Variable += Target}
04/22/23 Aspectual Components 24
class System{ String id = “from Thing to edu.neu.ccs.demeter.Ident”; 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 System”+constraint+“to 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: traversalblack bold: structurepurple: advicered: parameters
Java code
04/22/23 Aspectual Components 25
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
04/22/23 Aspectual Components 26
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
04/22/23 Aspectual Components 27
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.
04/22/23 Aspectual Components 28
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).
04/22/23 Aspectual Components 29
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
04/22/23 Aspectual Components 30
Concepts needed(DJ classes)
• ClassGraph• Strategy (= Java String = traversal strategy)• Visitor
04/22/23 Aspectual Components 31
Adaptive Programming
Strategy
Objectdefines family of
ClassGraph
is use-case basedabstraction of
Bold namesrefer to DJclasses.
04/22/23 Aspectual Components 32
Adaptive Programming
StrategyObject
defines traversals of
04/22/23 Aspectual Components 33
Adaptive Programming
Strategy
Visitor
guides andinforms
04/22/23 Aspectual Components 34
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
04/22/23 Aspectual Components 35
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 documentationof your current systems.
04/22/23 Aspectual Components 36
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.
04/22/23 Aspectual Components 37
Summary
• We view components as slices of behavior• Aspectual components
– reconcile between functional and object decomposition
– add new behavior and modify existing behavior – are a good model for AOP