Title: Expression evaluation
1Expression evaluation
- E S C.
- S int.
- C Op ltarg1gt E ltarg2gt E.
- Op A M.
- A . M .
2Class graph Find undefined things
Fig. UML1
Ident
definedThings
System
Thing
usedThings
def
S
Definition
T
body
Body
D
B
definedThings from System bypassing Body to
Thing usedThings from System through Body to
Thing
3M1 Equation System
Fig. Eq1
EquationSystem
equations
Equation_List
Ident
Variable
lhs
Equation
Numerical
rhs
Expression_List
Simple
args
Expression
op
Add
Compound
4CS1 UML class diagram Grammar
Fig. G1
Entry
0..
EParse
entries
Grammar
BParse
Production
rhs
Body
Part
parts
lhs
NonTerm
0..
Concrete
Abstract
5YOUR PROJECTclass graph
6Java Program Adaptive Method with DJ
- class System
- String id from Thing to edu.neu.ccs.demeter.I
dent - void repUndef(ClassGraph cg)
- checkDefined(cg, getDefThings(cg))
- HashSet getDefThings(ClassGraph cg)
- String definedThings
- "from System bypassing Body to Thing"
- 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, definedThings, v)
- return (HashSet)v.getReturnValue()
-
repUndef is a modular unit of crosscutting
implementation. Ad-hoc implementation may cut
across 100 classes.
green traversal black bold structure purple
advice red parameters
7Java Program Adaptive Method with DJ
- void checkDefined(ClassGraph cg, final HashSet
classHash) - String usedThings
- from System through Body to Thing"
- cg.traverse(this, usedThings, new Visitor()
- void before(Thing v) Ident vn cg.fetch(v,
vi) - if (!classHash.contains(vn))
- System.out.println("The object "
vn - " is undefined.")
- )
-
8Control Tangling and Scattering of Class
Structure, Traversals andTraversal Advice
9Aspect-Oriented Programming
- Separating the following cross-cutting concerns
- Object Structure
- Traversals through Objects
- Advice on Traversals
- New behaviors based on collaborating objects
- Focus on those four concerns only. They appear
frequently.
10Why crosscutting?
overall graph object structure green graph
traversal purple advice
r0
BusList
Route1BusRoute
buses
busStops
BusStopList
Bus15DieselPowered
passengers
CentralSquareBusStop
waiting
PersonList
PersonList
JoanPerson
PaulPerson
SeemaPerson
EricPerson
r
r
11Why aspects Oblivious
- Object Structure
- does not have to know about traversals and advice
on traversals - Traversals
- dont have to know about advice on traversals
- Advice on Traversals
- has to know minimally about object structure and
traversals
12Ad-hoc Implementationof three concerns
- Leads to lots of tangled code with numerous
disadvantages - The question is not how to eliminate the tangling
but how to reduce it - AOP is about tangling control the implementation
of crosscutting concerns - Crosscutting will always lead to some tangling at
code level
13Example
- Check whether all used entities are defined.
- Object structure, traversal (basically an
introduction), advice on traversal
14Find undefined things
definedThings
System
Thing
usedThings
Definition
Body
definedThings from System bypassing Body to
Thing usedThings from System through Body to
Thing
15M1 Equation System
Fig. Eq1
EquationSystem
equations
Equation_List
Ident
Variable
lhs
Equation
Numerical
rhs
Expression_List
Simple
args
Expression
op
Add
Compound
16Name map
Definition ClassDef Production
Equation
17High-level description
- It is useful to have a high-level description of
the collaboration besides the Java source code.
Useful documentation. - Ultimately we are interested in the executable
form of the collaboration (Java source code).
18Collaboration 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
19Collaboration with strategies
- collaboration COLLECT
- role System
- out HashSet collect()
- defined()(uses collect, definedThings)
- used()(uses collect, usedThings)
- in definedThings
- from System bypassing Body to Thing
- in usedThings
- from System through Body to Thing
- role Body
- role Thing
- role Definition
20Use of collaboration Adapter
- Need to provide the expected methods (in methods)
and provide name map. - name map
- System EquationSystem
- Definition Equation
- Body Expression
- Thing Variable
- expected methods
- in definedThings // use default
- in usedThings // use default
21What is an aspect?
- An aspect is a modular unit of crosscutting
implementation. - A Java method is a modular unit.
- Can we make a Java method an aspect?
- Yes, we call such methods adaptive methods.
- They cut across many classes in an ad-hoc
implementation.
22Java Program Adaptive Method
- class System
- String id from Thing to edu.neu.ccs.demeter.I
dent - void repUndef(ClassGraph cg)
- checkDefined(cg, getDefThings(cg))
- HashSet getDefThings(ClassGraph cg)
- String definedThings
- "from System bypassing Body to Thing"
- 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, definedThings, v)
- return (HashSet)v.getReturnValue()
-
green traversal black bold structure purple
advice red parameters
23Java Program Adaptive Method
- void checkDefined(ClassGraph cg, final HashSet
classHash) - String usedThings
- from System through Body to Thing"
- cg.traverse(this, usedThings, new Visitor()
- void before(Thing v) Ident vn cg.fetch(v,
id) - if (!classHash.contains(vn))
- System.out.println("The object "
vn - " is undefined.")
- )
-
24After applying name map
- For now we manually edit the Java program.
25Java Program with less tangling
- class EquationSystem
- String id from Variable to
edu.neu.ccs.demeter.Ident - void repUndef(ClassGraph cg)
- checkDefined(cg, getDefThings(cg))
- HashSet getDefThings(ClassGraph cg)
- String definedThings
- "from EquationSystem bypassing
Expression to Variable" - Visitor v new Visitor()
- HashSet return_val new HashSet()
- void before(Variable v1)
- return_val.add(cg.fetch(v1, id) )
- public Object getReturnValue()return
return_val - cg.traverse(this, definedThings, v)
- return (HashSet)v.getReturnValue()
-
green traversal black bold structure purple
advice red parameters
26Java Program with less tangling
- void checkDefined(ClassGraph cg, final HashSet
classHash) - String usedThings
- from EquationSystem through Expression
to Variable" - cg.traverse(this, usedThings, new Visitor()
- void before(Variable v) Ident vn
cg.fetch(v, id) - if (!classHash.contains(vn))
- System.out.println("The object "
vn - " is undefined.")
- )
-
27Tangling is localizedScattering eliminated
- Instead of having code spread across several
classes, it is localized in one class. - Java program is describing the abstract pattern
behind the computation of interest checking
whether used entities are defined. - Tangling control through abstraction of patterns.
We abstract away from structure.
28CS1 UML class diagram ClassG
definedThings from ClassG bypassing Body to
ClassName
Entry
0..
EParse
entries
ClassG
BParse
ClassDef
Body
Part
parts
className
0..
ClassName
Concrete
Abstract
29CS1UML class diagram ClassG
usedThings from ClassG through Body to ClassName
Entry
0..
EParse
entries
ClassG
BParse
ClassDef
Body
Part
parts
className
0..
ClassName
Concrete
Abstract
30M1 Equation System
Fig. Eq1
EquationSystem
equations
Equation_List
Ident
Variable
lhs
Equation
Numerical
rhs
Expression_List
Simple
args
Expression
op
Add
Compound
31M1 Equation System
definedThings from EquationSystem bypassing
Expression to Variable
Fig. Eq2
EquationSystem
equations
Equation_List
Ident
lhs
Equation
Variable
Numerical
rhs
Simple
args
Expression_List
Expression
S
T
op
Add
Compound
D
B
32M1 Equation System
usedThings from EquationSystem through
Expression to Variable
Fig. Eq3
EquationSystem
equations
Equation_List
Ident
lhs
Equation
Variable
Numerical
rhs
Simple
args
Expression_List
Expression
S
T
op
Add
Compound
D
B
33 Equation System Object
Fig. Eq4
equations
esEquationSystem
elsEquation_List
i1Ident
lhs
e1Equation
v1Variable
rhs
i2Ident
v2Variable
34M1 Equation System
usedThings from EquationSystem through
Expression to Variable
Example x 1.0 . y ( x 4.0). z ( x y).
EquationSystem ltequationsgt List(Equation). Equat
ion ltlhsgt Variable ltrhsgt Expression
.. Variable Ident. Expression Simple
Compound. Simple Variable Numerical. Compound
( Op ltargsgt List(Expression) ). Op Add
Mul. Add . Mul . Numerical float.
35M1 Equation System
definedThings from EquationSystem bypassing
Expression to Variable
Example x 1.0 . y ( x 4.0). z ( x y).
EquationSystem ltequationsgt List(Equation). Equat
ion ltlhsgt Variable ltrhsgt Expression
.. Variable Ident. Expression Simple
Compound. Simple Variable Numerical. Compound
( Op ltargsgt List(Expression) ). Op Add
Mul. Add . Mul . Numerical float.
36CS1 UML class diagram Grammar
Fig. G1
Entry
0..
EParse
entries
Grammar
BParse
Production
rhs
Body
Part
parts
lhs
NonTerm
0..
Concrete
Abstract
37CS1 UML class diagram Grammar
Fig. G2
definedThings from Grammar bypassing Body to
NonTerm
Entry
0..
EParse
entries
Grammar
BParse
Production
rhs
Body
Part
parts
lhs
NonTerm
0..
S
T
Concrete
Abstract
D
B
38CS1UML class diagram Grammar
usedThings from Grammar through Body to NonTerm
Fig. G3
Entry
0..
EParse
entries
Grammar
BParse
Production
Body
rhs
Part
parts
lhs
NonTerm
0..
S
T
Concrete
Abstract
D
B
39What DJ adds to AspectJ
- Point cut definitions based on connectivity in
class graph. - Define point cuts by specifying a (traversal)
program based on class graph. - Point cut reduction (high-level point cut
designator) free programmer from details of
class graph.
40Context Switch
- Textbook and project
- Chapter 7 Before The Project
- Chapter 6 While You are Coding