Download presentation

Presentation is loading. Please wait.

Published byCaden Herman Modified over 2 years ago

2
1 Shyness in Programming Karl Lieberherr Demeter Research Group Northeastern University Boston

3
2 Coupling Aspect-Oriented and Adaptive Programming: Shyness in Programming PhD Visitation Weekend 2003

4
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").

5
4 MIT Technology Review 2001 Aspect-oriented programming is called “adaptive programming” at Northeastern University.

6
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.

7
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?

8
7 Scattering and Tangling: Static aspect i is scattered across many classes (i = 1,2,3) class X tangles aspects 1, 2 and 3 aspect1aspect2aspect3 class A consisting of three aspects classes for aspect1 classes for aspect2 classes for aspect3 Class X class diagram Adding to classes

9
8 Scattering and Tangling: Dynamic program execution involving three aspects (colors r b g) program call tree (classes executing method calls) Each aspect (colors) is scattered across many classes (shapes) Class tangles all three aspects At those calls the aspect enhances the behavior classes this(s) target(t) f(..) Enhancing calls t.f(..);

10
9 AP-Concern-shy Program with multiple building blocks, say b1:B1 and b2:B2, that are woven together: b1*b2. b1 relies only on partial information about b2 which makes b1 more robust and reusable. Goal: b1 should be loosely coupled to b2. AP-Concern-shy –AP-Structure-shy AP-WildCard AP-Strategy –AP-Call –AP-Demeter

11
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.

12
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) Best of both worlds 50 pages of theory

13
12 Adaptive Programming. AP-Concern-shy –AP-Structure-shy AP-WildCard AP-Strategy –AP-Call –AP-Demeter AP-Concern-shy –AP-Graph-shy AP-CallGraph-shy AP-ClassGraph-shy –AP-WildCard –AP-Strategy Alternative organization: X-shy subX-shy Mechanism-to-achieve-shyness

14
13 AP-Structure-shy Program with multiple building blocks including b1and b2:Graph, 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. AP-Concern-shy –AP-Structure-shy AP-WildCard AP-Strategy –AP-Call –AP-Demeter

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

16
15 AP-Strategy Program with multiple building blocks including b1:Strategy and b2:Graph, 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. AP-Concern-shy –AP-Structure-shy AP-WildCard AP-Strategy –AP-Call –AP-Demeter One contributor: Ignacio Silva-Lepe PhD 1994 Currently at IBM Watson Research Lab

17
16 A General Strategy-based Adaptive Mechanism 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. From TOPLAS 2003 paper (Lieberherr, Patt-Shamir, Orleans)

18
17 Middle graph: Abstraction barrier Bottom tree: select subtrees A B A B C Top graph: subgraph of transitive closure of middle layer C A B c1:C c2:C c3:C

19
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.

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

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

22
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 …)

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

24
23 AP-Demeter Program with multiple building blocks including b1:Strategy and b2:ClassGraph, 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. AP-Concern-shy –AP-Structure-shy AP-WildCard AP-Strategy –AP-Call –AP-Demeter

25
24 AP-DJ Program in terms of ClassGraph-, Strategy- and Visitor-objects. Example: –in Java: cg.traverse(o, s, v); AP-Concern-shy –AP-Structure-shy AP-WildCard AP-Strategy –AP-Call –AP-Demeter The easiest tool to learn good structure-shy programming

26
25 AP-DAJ 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(); AP-Concern-shy –AP-Structure-shy AP-WildCard AP-Strategy –AP-Call –AP-Demeter

27
26 Isolated join points crosscutting Connected join points base Adaptive to family of bases

28
27 Demeter crosscutting I Connected join points Class graph or Object graph From Company to Salary From BusRoute via BusStop to Person Adaptive to family of class graphs

29
28 Isolated join points Demeter crosscutting II Connected join points Static call graph or Dynamic call graph …_salary(Employee, Object) From Company to Salary Adaptive to family of traversal call graphs

30
29 Isolated join points AspectJ crosscutting I Class graph or Object graph Company.cache(){}Vector BusRoute.busses;

31
30 Isolated join points AspectJ crosscutting II Connected join points Static call graph or Dynamic call graph target(Employee) cflow Adaptive to family of call graphs

32
31 Demeter crosscutting Connected join points Graph From BusRoute via Bus to Person Isolated join points …_salary(Employee, Object) Adaptive to family of graphs

33
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?

34
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

35
34 The End

36
35 Crosscutting in Demeter generated Java program structure-shy functionality structure synchronization Demeter program replicated!

37
36 range of AOP languages means of … join points add memberssignaturesclass members static JPM DemeterJ, DAJ dynamic JPM static JPM 1 static JPM 2 static JPM 3 AspectJ dynamic JPM JPM when traversal reaches object or edge class members points in execution call, get, set… join points visitor method signatures traversal spec. s class graph g class names class graph signatures w/ wildcards & other properties of JPs identifying visitor method bodies s + g (result = traversal implementation) add members class graph with tokens=grammar (result = parsing and printing implementation) advice specifying semantics at

38
37 Adaptiveness The next 7 viewgraphs show how two traversals (parts of an adaptive program) adapt to two different class graphs.

39
38 Class graph: Find undefined things System Body Thing * * * definedThings usedThings definedThings= from System bypassing Body to Thing usedThings = from System through Body to Thing * Definition def body Ident S D T B

40
39 M1: Equation System EquationSystem Equation_List Equation Variable equations * lhs rhs Expression Simple Compound Numerical Expression_List * Add op args Ident

41
40 M1: Equation System definedThings = from EquationSystem bypassing Expression to Variable EquationSystem Equation_List Equation Variable equations * lhs rhs Expression Simple Compound Numerical Expression_List * Add op args Ident S D T B

42
41 M1: Equation System usedThings = from EquationSystem through Expression to Variable EquationSystem Equation_List Equation Variable equations * lhs rhs Expression Simple Compound Numerical Expression_List * Add op args Ident S D T B

43
42 CS1: Grammar Grammar EParse BParse Production Entry0..* entries Body Part NonTerm 0..* parts Concrete Abstract lhs rhs

44
43 CS1: Grammar Grammar EParse BParse Production Entry0..* entries Body Part NonTerm 0..* parts Concrete Abstract lhs definedThings = from Grammar bypassing Body to NonTerm rhs S D T B

45
44 CS1:Grammar Grammar EParse BParse Production Entry0..* entries Body Part NonTerm 0..* parts Concrete Abstract lhs usedThings = from Grammar through Body to NonTerm rhs S D T B

46
45 P1P1 P2P2 P3P3 P1P1 P6P6 P2P2 P5P5 P3P3 P4P4 P1P1 P2P2 Software Structure with ACs 45 P1P1 P2P2 P3P3 P1P1 P6P6 P2P2 P5P5 P3P3 P4P4 P1P1 P2P2 Software Structure with ACs 45 P1P1 P2P2 P3P3 P1P1 P6P6 P2P2 P5P5 P3P3 P4P4 P1P1 P2P2 Software Structure with ACs

47
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 b1*b2 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

48
47 Scattering B2 is a graph. Count number of nodes and edges that are enhanced. Scat(b1*b2) = number of nodes and edges in b2 enhanced by b1. The higher the number, the more the crosscutting. A program b1*B2 is crosscutting if there is an infinite sequence R1, R2, … of B2 so that Scat(b1*R1), Scat(b1*R2), … is strictly increasing.

Similar presentations

OK

UBC software modularity group 1/14/02 UCSD1 Discussion with Kiczales at UBC Ontology of AOP Ontology is the study of what there is, an inventory of what.

UBC software modularity group 1/14/02 UCSD1 Discussion with Kiczales at UBC Ontology of AOP Ontology is the study of what there is, an inventory of what.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on channels of distribution of pepsi Ppt on c++ programming language Ppt on hot and cold places Ppt on smoking and drinking Ppt on self awareness Ppt on knowledge management Shown by appt only Ppt on guru granth sahib ji Ppt on standing order act score Ppt on bio inspired robotics