AOSD and the Law of Demeter: Shyness in Programming - PowerPoint PPT Presentation

About This Presentation
Title:

AOSD and the Law of Demeter: Shyness in Programming

Description:

PhD Visitation Weekend 2003. 3. Our Intuition behind AOP ... to the class graph ('painting the class graph in broad strokes with code') and ... – PowerPoint PPT presentation

Number of Views:94
Avg rating:3.0/5.0
Slides: 48
Provided by: karljlie
Learn more at: https://www2.ccs.neu.edu
Category:

less

Transcript and Presenter's Notes

Title: AOSD and the Law of Demeter: Shyness in Programming


1
AOSD and the Law of Demeter Shyness in
Programming
  • Karl Lieberherr
  • Demeter Research Group
  • Northeastern University
  • Boston

2
Coupling Aspect-Oriented and Adaptive
ProgrammingShyness in Programming
  • PhD Visitation Weekend 2003

3
Our Intuition behind AOP
  • Our Aspect-Oriented Programming (AOP) intuition
    has been "adaptiveness". It comes in two
    flavors adaptiveness
  • to the class graph ("painting the class graph in
    broad strokes with code") and
  • to the call graph of the traversal ("picking
    points in the graph where additional code gets
    called").

4
MIT Technology Review2001
  • Aspect-oriented programming is called adaptive
    programming at Northeastern University.

5
Definitions
  • y is x-shy if
  • (1) y relies only on minimal information of x
  • (2) y can adapt to small changes in x
  • (3) y is loosely coupled with x
  • (4) y can work with x1, x2, ... which are close
    or similar to x.
  • What is a concern? A concern is something that
    the programmer cares about.

6
Examples of concerns the programmer has to deal
with
  • Production concerns
  • How do I compute the price allowing for multiple
    pricing schemes?
  • Non-Production concerns
  • What do I have to print to understand why this
    program does not work?
  • Are all objects of class A created in class
    Afactory?

7
Scattering and Tangling Static
  • aspecti is scattered across many classes (i
    1,2,3)
  • class X tangles aspects 1, 2 and 3

class A consisting of three aspects
aspect1
aspect2
aspect3
class diagram
Class X
classes for aspect1
classes for aspect3
classes for aspect2
Adding to classes
8
Scattering and Tangling Dynamic
  • Each aspect (colors) is scattered across many
    classes (shapes)
  • Class tangles all three aspects

program execution involving three aspects
(colors r b g)
this(s)
f(..)
target(t)
program call tree (classes executing method
calls)
Enhancing calls
t.f(..)
classes
At those calls the aspect enhances the behavior
9
AP-Concern-shy
  • AP-Concern-shy
  • AP-Structure-shy
  • AP-WildCard
  • AP-Strategy
  • AP-Call
  • AP-Demeter
  • Program with multiple building blocks, say b1B1
    and b2B2, that are woven together b1b2. b1
    relies only on partial information about b2 which
    makes b1 more robust and reusable. Goal b1
    should be loosely coupled to b2.

10
Law of Demeter (LoD) for Concerns
  • A concern implementation should not rely on too
    much information about other concern
    implementations.
  • (Classic LoD A method should not rely on too
    much information about other classes/objects.)

Ian Holland PhD 1992 Vice President of
Architecture and Systems Engineering at Kronos
Incorporated in Chelmsford, MA. 2200 empls.
11
Adaptive Programming.
  • AP-Concern-shy concerns shy of other concerns
  • AP-Structure-shy concerns shy of graph structure
  • AP-WildCard aspects shy through wildcards
  • AspectJ , .., this, target, args, call,
    execution, (call graph)
  • AP-Strategy three level model using strategies
  • AP-Call aspects shy of call graph using
    strategies
  • AspectJ cflow
  • AP-Demeter behavior shy of class graph using
    strategies advice on traversal
  • AP-DJ ClassGraph, Strategy, Visitor (in Java)
  • AP-DAJ Strategy enhances ClassGraph Visitor
    enhances traversal defined by Strategy (in
    AspectJ)
  • AP-DemeterJ (new programming language)

50 pages of theory
Best of both worlds
12
Adaptive Programming.
  • AP-Concern-shy
  • AP-Structure-shy
  • AP-WildCard
  • AP-Strategy
  • AP-Call
  • AP-Demeter

Alternative organization
  • AP-Concern-shy
  • AP-Graph-shy
  • AP-CallGraph-shy
  • AP-ClassGraph-shy
  • AP-WildCard
  • AP-Strategy

X-shy subX-shy Mechanism-to-achieve-shyness
13
AP-Structure-shy
  • AP-Concern-shy
  • AP-Structure-shy
  • AP-WildCard
  • AP-Strategy
  • AP-Call
  • AP-Demeter
  • Program with multiple building blocks including
    b1and b2Graph, that are woven together. b1
    relies only on partial information about b2 which
    makes b1 more robust and reusable. Goal b1
    should be loosely coupled to b2. b1 enhances b2
    at nodes and edges.

14
AP-WildCard
  • AP-Concern-shy
  • AP-Structure-shy
  • AP-WildCard
  • AP-Strategy
  • AP-Call
  • AP-Demeter
  • Program with multiple building blocks including
    b1 and b2Graph, that are woven together. b1 uses
    wildcard techniques which makes b1 more robust
    and reusable. Goal b1 should be loosely coupled
    to b2.

15
AP-Strategy
One contributor Ignacio Silva-Lepe PhD
1994 Currently at IBM Watson Research Lab
  • AP-Concern-shy
  • AP-Structure-shy
  • AP-WildCard
  • AP-Strategy
  • AP-Call
  • AP-Demeter
  • Program with multiple building blocks including
    b1Strategy and b2Graph, that are woven
    together. b1 reveals only partial information
    about b2 which makes b1 more robust and reusable.
    b1 is written against an abstraction of b2 so
    that the application to b2 is well defined. Goal
    b1 should be loosely coupled to b2.

16
A General Strategy-based Adaptive Mechanism
From TOPLAS 2003 paper (Lieberherr, Patt-Shamir,
Orleans)
  • Three layers of graphs Bottom, Middle, Top
  • Bottom layer trees to select subtrees guided by
    top layer. Each bottom layer tree has a graph
    from the
  • Middle layer associated with it that contains
    meta-information about the bottom layer tree.
    Acts as an abstraction barrier between the top
    and bottom layers. Used to reduce search space.
  • Top layer graph is basically a subgraph of the
    transitive closure of the middle layer graph,
    decorated with additional information attached to
    the edges.

17
Top graph subgraph of transitive closure of
middle layer
B
A
C
Middle graph Abstraction barrier
B
A
C
Bottom tree select subtrees
B
c1C c2C c3C
A
18
Strategy-based adaptiveness
  • The call graph application (AspectJ)
  • Top computational pattern,
  • Middle static call graph,
  • Bottom call tree.
  • The standard application (Demeter)
  • Top strategy graph,
  • Middle class graph,
  • Bottom object trees.

19
AP-Call
  • AP-Concern-shy
  • AP-Structure-shy
  • AP-WildCard
  • AP-Strategy
  • AP-Call
  • AP-Demeter
  • Program with multiple building blocks including
    b1CrossCut and b2CallGraph, that are woven
    together. b1 reveals only partial information
    about b2 which makes b1 more robust and reusable.
    Advice on b2 at b1.

20
AP-AspectJ
  • AP-Concern-shy
  • AP-Structure-shy
  • AP-WildCard
  • AP-Strategy
  • AP-Call
  • AP-Demeter
  • Program with multiple building blocks including
    b1PointCut and b2CallGraph, that are woven
    together. b1 reveals only partial information
    about b2 which makes b1 more robust and reusable.
    Advice on b2 at b1.

21
AP-AspectJ
  • Many AspectJ programs are adaptive (designed for
    a family of Java programs)
  • Context Java program or its execution tree
    (lexical joinpoints or dynamic join points)
  • Features enabling adaptiveness
  • , .. (wildcards)
  • cflow, (graph transitivity)
  • this(s), target(s), args(a), call (),
    (inheritance as wild card)
  • pc(Object s, Object t)
  • this(s) target(t) call( f )

22
AP-COOL
  • AP-Concern-shy
  • AP-Structure-shy
  • AP-WildCard
  • AP-Strategy
  • AP-Call
  • AP-Demeter
  • Program with multiple building blocks including
    b1Coordinator and b2CallGraph, that are woven
    together. b1 reveals only partial information
    about b2 which makes b1 more robust and reusable.
    Advice on b2 at b1.

Crista Lopes, PhD 1997 Assistant Professor at UC
Irvine, first PhD thesis on AOP.
23
AP-Demeter
  • AP-Concern-shy
  • AP-Structure-shy
  • AP-WildCard
  • AP-Strategy
  • AP-Call
  • AP-Demeter
  • Program with multiple building blocks including
    b1Strategy and b2ClassGraph, that are woven
    together. b1 reveals only partial information
    about b2 which makes b1 more robust and reusable.
    Advice on traversal defined by b1 and b2.

24
AP-DJ
  • AP-Concern-shy
  • AP-Structure-shy
  • AP-WildCard
  • AP-Strategy
  • AP-Call
  • AP-Demeter
  • Program in terms of ClassGraph-, Strategy- and
    Visitor-objects.
  • Example
  • in Java cg.traverse(o, s, v)

The easiest tool to learn good structure-shy progr
amming
25
AP-DAJ
  • AP-Concern-shy
  • AP-Structure-shy
  • AP-WildCard
  • AP-Strategy
  • AP-Call
  • AP-Demeter
  • Program in terms of Strategy-objects that
    introduce traversal methods into
    ClassGraph-objects (adaptiveness to class graph).
  • Enhance the execution of the traversal methods
    with Visitor-objects that may modify the run-time
    traversal (adaptiveness to the traversal
    execution).
  • Example In AspectJ declare traversal f() s V
    o.f()

26
crosscutting
base
Adaptive to family of bases
Connected join points
Isolated join points
27
Demeter crosscutting I
Class graph or Object graph
From Company to Salary
Adaptive to family of class graphs
From BusRoute via BusStop to Person
Connected join points
28
Demeter crosscutting II
Static call graph or Dynamic call graph
From Company to Salary
Adaptive to family of traversal call graphs
_salary(Employee, Object)
Connected join points
Isolated join points
29
AspectJ crosscutting I
Class graph or Object graph
Company.cache()
Vector BusRoute.busses
Isolated join points
30
Static call graph or Dynamic call graph
AspectJ crosscutting II
Adaptive to family of call graphs
cflow
target(Employee)
Connected join points
Isolated join points
31
Demeter crosscutting
Graph
From BusRoute via Bus to Person
Adaptive to family of graphs
_salary(Employee, Object)
Connected join points
Isolated join points
32
How are AP and AOP coupled?
  • AOP module-shy programming
  • Modularize programs that cut across modules (with
    minimal reliance on information in modules).
  • Programming is module-shy if the modular
    structure of the program does not prevent
    concerns that cut across other concerns to be
    modularized.
  • AP concern-shy programming

Can we view concern implementations as modules?
33
Many open questions
  • Doug Orleans Simple model of AOP Fred
  • Johan Ovlinger Modules and Aspects
  • Pengcheng Wu Statically Executable Advice
  • Theo Skotiniotis Contracts for Aspects

34
The End
35
Crosscutting in Demeter
generated Java program
Demeter program
structure-shy functionality
structure
replicated!
synchronization
36
range of AOP languages
means of join points

JPM
join points
identifying
specifying semantics at
AspectJ dynamic JPM
points in execution call, get, set
signaturesw/ wildcards other properties of JPs
advice
add members
signatures
class members
static JPM
  • DemeterJ, DAJ
  • dynamic JPM
  • static JPM 1
  • static JPM 2
  • static JPM 3

when traversal reaches object or edge class
members class members class members
visitor method signatures traversal spec. s class
graph g class names class graph
visitor method bodies s g (result traversal
implementation) add members class graph with
tokensgrammar (result parsing and printing
implementation)
37
Adaptiveness
  • The next 7 viewgraphs show how two traversals
    (parts of an adaptive program) adapt to two
    different class graphs.

38
Class graph Find undefined things
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
39
M1 Equation System
EquationSystem
equations
Equation_List
Ident

Variable
lhs
Equation
Numerical
rhs
Expression_List
Simple
args
Expression

op
Add
Compound
40
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
41
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
42
CS1 Grammar
Entry
0..
EParse
entries
Grammar
BParse
Production
rhs
Body
Part
parts
lhs
NonTerm
0..
Concrete
Abstract
43
CS1 Grammar
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
44
CS1Grammar
usedThings from Grammar through Body to NonTerm
Entry
0..
EParse
entries
Grammar
BParse
Production
Body
rhs
Part
parts
lhs
NonTerm
0..
S
T
Concrete
Abstract
D
B
45
Software Structure with ACs
Software Structure with ACs
Software Structure with ACs
P1
P1
P1
P2
P2
P2
P3
P3
P3
P1
P1
P1
P4
P4
P4
P3
P3
P3
P5
P5
P5
P2
P2
P2
P2
P2
P2
P6
P6
P6
P1
P1
P1
45
45
45
46
AP-structure-shy notion of crosscutting
  • B2 program and its execution trees or an
    abstraction thereof UML class diagram and its
    object diagrams.
  • A program b1b2 is aspect-oriented if it is
    crosscutting.
  • Examples Adaptive, aspect-oriented programs
    Policies (Concurrency, Distribution,
    Authentication, Logging), Adaptive Method, Law of
    Demeter Checker in AspectJ

47
Scattering
  • B2 is a graph. Count number of nodes and edges
    that are enhanced. Scat(b1b2) number of nodes
    and edges in b2 enhanced by b1. The higher the
    number, the more the crosscutting.
  • A program b1B2 is crosscutting if there is an
    infinite sequence R1, R2, of B2 so that
    Scat(b1R1), Scat(b1R2), is strictly
    increasing.
Write a Comment
User Comments (0)
About PowerShow.com