Expression evaluation E : S | C. S = int. C = Op E E. Op : A | M. A = “+”. M = “*”.

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

Aspect Oriented Programming. AOP Contents 1 Overview 2 Terminology 3 The Problem 4 The Solution 4 Join point models 5 Implementation 6 Terminology Review.
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 32 Slide 1 Aspect-oriented Software Development.
1 Shyness in Programming Karl Lieberherr Demeter Research Group Northeastern University Boston.
1 Shyness in Programming Karl Lieberherr Demeter Research Group Northeastern University Boston.
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
University of British Columbia Software Practices Lab CAS Seminar 06 Fluid AJ - A Simple Fluid AOP Tool Terry Hon Gregor Kiczales.
UML class diagrams and XML schemas Karl Lieberherr UBS AG Northeastern University.
1 Model Interface Implementation for Two-Way Obliviousness in Aspect-Oriented Modeling Presented by Wuliang Sun Department of Computer Science Baylor University.
Outline Introduction Problem Statement Object-Oriented Design Aspect-Oriented Design Conclusion Demo.
3/7/2003Bioinformatics1 How To Address Rapidly Changing Data Representations in an Evolving Scientific Domain Using Aspect-oriented Programming Techniques.
Object-Oriented Software Testing. C-S 5462 Object-Oriented Software Testing Research confirms that testing methods proposed for procedural approach are.
Demeter Interfaces: AP without Surprises Prof. Karl Lieberherr and Therapon Skotiniotis, Jeffrey Palm.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Aspect Oriented Programming Razieh Asadi University of Science & Technology Mazandran Babol Aspect Component Based Software Engineering (ACBSE)
Integrating Independent Components with On-Demand Remodularization based on OOPSLA 2002 paper by Mira Mezini Klaus Ostermann Prepared by Karl Lieberherr.
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 32 Slide 1 Aspect-oriented Software Development 1.
Aspect Oriented Programming Sumathie Sundaresan CS590 :: Summer 2007 June 30, 2007.
Take-Home Final COM 3205 Fall Stamp Coupling Def: data structure is passed as parameter, but called method operates on only some of the` individual.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
3/7/2003 ABB rapid change 1 How To Address Rapidly Changing Data Representations in an Evolving Scientific Domain Using Aspect-oriented Programming Techniques.
Slides for Gregor Kiczales Two versions –short version: Crosscutting capabilities for Java and AspectJ through DJ (4 viewgraphs only) –long version: Controlling.
AOSD1 Aspect-Oriented Software Design Karl Lieberherr Theo Skotiniotis.
Not only mark-up languages! There are other many other grammar formalisms and tools than XML. Some of them standardized (ASN). Even XML does not always.
AOP-1 Aspect Oriented Programming. AOP-2 Aspects of AOP and Related Tools Limitation of OO Separation of Concerns Aspect Oriented programming AspectJ.
John J. Sung TA Consulting. Motivation for TraversalJ KL Enterprises identified AOP Enter into the AOP market early Add value by adding traversals to.
System Body Thing * * Definition Fig. UML1 def body Ident S D T B definitions things.
AOP Foundations Doug Orleans Karl Lieberherr. What we did earlier AOP languages have the following main elements: –a join point model (JPM) wrt base PL.
Features of AOP languages AOP languages have the following main elements: –a join point model (JPM) wrt base PL –a specification language for expressing.
System Body Thing * * Definition Fig. UML1 def body Ident S D T B definitions things.
Pattern Language for AP1 Pattern Language for Adaptive Programming (AP) Karl Lieberherr Northeastern University.
CSG 7111 Structure and Interpretation of an Aspect Language for Datatype Karl Lieberherr.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University IWPSE 2003 Program.
Demeter Aspects We study techniques for the emerging area of Aspect-Oriented Software Development and focus on the following areas:  Aspectual Collaborations.
Aspect Oriented Development Alex Beatty.  Purpose  Cross-cutting Concerns  Join Points, Pointcuts, and Advices  Weaving  Invasive vs. Non-Invasive.
Demeter Interfaces: AP without Surprises Prof. Karl Lieberherr and Therapon Skotiniotis, Jeffrey Palm.
Translating Traversals to AspectJ. Outline Motivation Demeter Process for Traversals AspectJ Translation Process.
DJ: traversal-visitor-style programming in Java Josh Marshall/ Doug Orleans Want to add more on traversal through collections and Aspectual Components.
Problem with Java and how it causes a problem for DJ.
AOP/cross-cutting What is an aspect?. An aspect is a modular unit that cross-cuts other modular units. What means cross-cutting? Apply AOP to AOP. Tease.
Good for DJ over Java Extending traversals for b..* –returning a single object instead of a collection (Find) –modifying the collection (Add, Delete)
Why Should You Care About Aspect-Oriented Programming? Karl Lieberherr CCIS.
Methods.
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.
COM1205 TraversalJ Project* Pengcheng Wu Feb.25,2003.
AO Mechanisms in Demeter1 Discussion with Gregor Kiczales at UBC Ontology of AOP Ontology is the study of what there is, an inventory of what exists. An.
1 Aspectual Caml an Aspect-Oriented Functional Language Hideaki Tatsuzawa Hidehiko Masuhara Akinori Yonezawa University of Tokyo.
Talk only to your friends that share the same concerns (Law of Demeter for Concerns) Midterm Review February 2004.
Pattern Language for AP1 Pattern Language for Adaptive Programming (AP) Karl Lieberherr Northeastern University.
Features of AOP languages AOP languages have the following main elements: –a join point model (JPM) wrt base PL –a specification language for expressing.
Viewgraphs for Semantics
Crosscutting Capabilities for Java and AspectJ through DJ
Structure and Interpretation of an Aspect Language for Datatype
Aspect-Oriented Programming with the Eclipse AspectJ plug-in
Discussion with Gregor Kiczales at UBC
For John.
Adaptive Object-Oriented Software Development
Software Design and Development
ADAPTIVE PROGRAMMING Sezen ERDEM December 2005.
Software Design and Development
Midterm Review CSU 670 Spring 2004.
Lecture 21: Crosscutting Aspect-Oriented Programming Background
Better Separation of Crosscutting Concerns with Aspectual Components
APPCs revisited 2/25/2019 APPCs revisited.
AOSD and the Law of Demeter: Shyness in Programming
Software Development CSU 670 Karl Lieberherr
Objects, components, and Frameworks with UML
Karl Lieberherr Doug Orleans
Presentation transcript:

Expression evaluation E : S | C. S = int. C = Op E E. Op : A | M. A = “+”. M = “*”.

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 Fig. UML1 def body Ident S D T B

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

CS1: UML class diagram Grammar Grammar EParse BParse Production Entry0..* entries Body Part NonTerm 0..* parts Concrete Abstract lhs rhs Fig. G1

YOUR PROJECT class graph

Java Program: Adaptive Method with DJ class System{ String id = “from Thing to edu.neu.ccs.demeter.Ident”; 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 repUndef is a modular unit of crosscutting implementation. Ad-hoc implementation may cut across 100 classes.

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."); }}});} } Java Program: Adaptive Method with DJ

Control Tangling and Scattering of Class Structure, Traversals and Traversal Advice

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

Why crosscutting? Route1:BusRoute :BusStopList busStops CentralSquare:BusStop :PersonList waiting Paul:PersonSeema:Person :BusList buses Bus15:DieselPowered :PersonList passengers Joan:Person Eric:Person r++; r=0; overall graph: object structure; green graph: traversal; purple: advice

Why aspects: Oblivious Object Structure –does not have to know about traversals and advice on traversals Traversals –don’t have to know about advice on traversals Advice on Traversals –has to know minimally about object structure and traversals

Ad-hoc Implementation of 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

Example Check whether all used entities are defined. Object structure, traversal (basically an introduction), advice on traversal

Find undefined things System Body Thing * * * definedThings usedThings definedThings= from System bypassing Body to Thing usedThings = from System through Body to Thing * Definition

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

Name map Definition ClassDef Production Equation

High-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).

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 { } }

Collaboration 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 { } }

Use 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

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

Java Program: Adaptive Method class System{ String id = “from Thing to edu.neu.ccs.demeter.Ident”; 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

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."); }}});} } Java Program: Adaptive Method

After applying name map For now we manually edit the Java program.

Java 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

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."); }}});} } Java Program with less tangling

Tangling is localized Scattering 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.

CS1: UML class diagram ClassG ClassG EParse BParse ClassDef Entry0..* entries Body Part ClassName 0..* parts Concrete Abstract className definedThings = from ClassG bypassing Body to ClassName

CS1:UML class diagram ClassG ClassG EParse BParse ClassDef Entry0..* entries Body Part ClassName 0..* parts Concrete Abstract className usedThings = from ClassG through Body to ClassName

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

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 Fig. Eq2 Ident S D T B

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 Fig. Eq3 Ident S D T B

Equation System Object equations lhs rhs Fig. Eq4 es:EquationSystem els:Equation_List e1:Equationv1:Variable i1:Ident v2:Variable i2:Ident

M1: Equation System EquationSystem = List(Equation). Equation = Variable “=“ Expression “.”. Variable = Ident. Expression : Simple | Compound. Simple : Variable | Numerical. Compound = “(“ Op List(Expression) “)”. Op : Add | Mul. Add = “+”. Mul = “*”. Numerical = float. Example: x = 1.0. y = (+ x 4.0). z = (* x y). usedThings = from EquationSystem through Expression to Variable

M1: Equation System EquationSystem = List(Equation). Equation = Variable “=“ Expression “.”. Variable = Ident. Expression : Simple | Compound. Simple : Variable | Numerical. Compound = “(“ Op List(Expression) “)”. Op : Add | Mul. Add = “+”. Mul = “*”. Numerical = float. Example: x = 1.0. y = (+ x 4.0). z = (* x y). definedThings= from EquationSystem bypassing Expression to Variable

CS1: UML class diagram Grammar Grammar EParse BParse Production Entry0..* entries Body Part NonTerm 0..* parts Concrete Abstract lhs rhs Fig. G1

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

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

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

Context Switch Textbook and project: –Chapter 7: Before The Project –Chapter 6: While You are Coding