DJ: traversal-visitor-style programming in Java Josh Marshall/ Doug Orleans Want to add more on traversal through collections and Aspectual Components.

Slides:



Advertisements
Similar presentations
1 Chapter 6: Extending classes and Inheritance. 2 Basics of Inheritance One of the basic objectives of Inheritance is code reuse If you want to extend.
Advertisements

OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Encapsulation by Subprograms and Type Definitions
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
(C) 1998 Tendril Software Inc. StructureBuilder Tendril Software Inc. OOPSLA ‘98 Demo Neeraj Sangal, President Tendril Software Karl.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
UML class diagrams and XML schemas Karl Lieberherr UBS AG Northeastern University.
Software Testing and QA Theory and Practice (Chapter 4: Control Flow Testing) © Naik & Tripathy 1 Software Testing and Quality Assurance Theory and Practice.
OOP Languages: Java vs C++
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
CS2110: SW Development Methods Design of methods (functions) Class design – CRC cards – UML class and sequence diagrams Software Design.
Computer Science II 810:062 Section 01 Session 2 - Objects and Responsibilities.
Integrating Independent Components with On-Demand Remodularization based on OOPSLA 2002 paper by Mira Mezini Klaus Ostermann Prepared by Karl Lieberherr.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
CSE 425: Object-Oriented Programming I Object-Oriented Programming A design method as well as a programming paradigm –For example, CRC cards, noun-verb.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
AP/DJ AP: a generic technology DJ: a low-learning-curve implementation of AP.
TOOLS USA '99 Interaction Schemata: Compiling Interactions to Code Neeraj Sangal, Edward Farrell, Tendril Software, Inc, Westford, MA
Introduction to Object Oriented Programming CMSC 331.
Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Inheritance and Polymorphism.
1/20/03A2-1 CS494 Interfaces and Collection in Java.
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.
Object Oriented Software Development
Features of AOP languages AOP languages have the following main elements: –a join point model (JPM) wrt base PL –a specification language for expressing.
Design Model Lecture p6 T120B pavasario sem.
Demeter Aspects We study techniques for the emerging area of Aspect-Oriented Software Development and focus on the following areas:  Aspectual Collaborations.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Ordered Linked Lists using Abstract Data Types (ADT) in Java Presented by: Andrew Aken.
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
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)
Zach Tatlock / Winter 2016 CSE 331 Software Design and Implementation Lecture 13 Generics 1.
R-customizers Goal: define relation between graph and its customizers, study domains of adaptive programs, merging of interface class graphs.
Interfaces. In order to work with a class, you need to understand the public methods  methods, return types,…  after you instantiate, what can you do.
Talk only to your friends that share the same concerns (Law of Demeter for Concerns) Midterm Review February 2004.
Unified Modeling Language (UML)
David Evans CS201J: Engineering Software University of Virginia Computer Science Lecture 5: Implementing Data Abstractions.
CS223: Software Engineering Lecture 26: Software Testing.
1 M206 Chapter 31: An Overview of Software Development 1.Defining the problem 2.Analyzing the requirement – constructing initial structural model 3.Analyzing.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Features of AOP languages AOP languages have the following main elements: –a join point model (JPM) wrt base PL –a specification language for expressing.
AP/DJ AP: a generic technology
Functional Programming
Sections Inheritance and Abstract Classes
Control Flow Testing Handouts
Good for DJ over Java Extending traversals for collections (b..*)
Interface, Subclass, and Abstract Class Review
Inheritance and Polymorphism
Behavioral Design Patterns
Outline of the Chapter Basic Idea Outline of Control Flow Testing
Types of Programming Languages
Demeter Aspects Who We Are Aspectual Collaborations
Lecture 6 Project review
ADAPTIVE PROGRAMMING Sezen ERDEM December 2005.
Third lecture Review Visitor pattern DemeterJ 12/25/2018 SD.
AP/DJ AP: a generic technology
Better Separation of Crosscutting Concerns with Aspectual Components
Third lecture Review Visitor pattern DemeterJ 2/17/2019 SD.
APPCs revisited 2/25/2019 APPCs revisited.
Chapter 9 Carrano Chapter 10 Small Java
Data Structures & Algorithms
SPL – PS1 Introduction to C++.
Presentation transcript:

DJ: traversal-visitor-style programming in Java Josh Marshall/ Doug Orleans Want to add more on traversal through collections and Aspectual Components

History Fall 1996: Lars Hansen: early proposal Johan Ovlinger: TAO Traversal automata by Wand and Ovlinger Doug Orleans: AP Library makes DJ possible David Wagstaff (Novell): Pure Java AP

Motivation Better to have an easy to use less powerful system than a harder to use more powerful system to get initial users. Build on Demeter/Java experience –through AP Library –visitor organization Extend Demeter/Java: generalize traversals: find, add, delete,...

DJ Features Name traversals Provide abstract visitor class Create class graph from Java source Compute traversals dynamically

Comparison DJ –interprets traversal strategies: slower, dynamic –only requires DJ package Demeter/Java –generates traversal code: faster, static –new programming language

Good for DJ over Java Extending traversals for collections (b..*) –returning a single object instead of a collection (Find) –modifying the collection (Add, Delete) –implementations are different for different implementations of collections

Embedding versus path control Embedding does mapping work once but requires mapping construct Path control may repeat mapping work

Reuse of an AC written with DJ Copy AC rename everything change path control: assumes original AC is written with path control Leads to duplication of code

UML Class Diagram Library Book 0..* books User users 0..* Copy copies 0..* book checkOutItems 0..* Boolean avail bN BookName UserId uId

UML Class Diagram Library Book 0..* books User users 0..* Copy copies 0..* book checkOutItems 0..* Boolean avail bN BookName UserId uId CheckOutItem copy

How can addition be expressed with ACs Required: participant graph Provided: modified participant graph: has all the paths in original but may have more

Interaction schema CheckOut { Library( Find-> Book Find(avail==true)-> c:Copy; Find-> u:User;) addCopy { u:User Add-> Copy; c:Copy Set(avail,false)-> Boolean } }//participants: Library, Book, Copy, User Checkout a book for a user

CheckOut (Library lib,BookName bN, UserId uId){ lib:Library( )-> Book Find(this.bN==bN)-> Book Find(avail==true)-> Find(avail==true)->c:Copy; Find(this.uId==uId)-> u:User;) addCopy { u:User Add(c)-> Copy; c:Copy Set(avail,false)-> Boolean } Compiler asks for information or determines it by rules

class Library { Copy CheckOut (Library lib,BookName bN, UserId uId){ Book b = lib.Find(“Book”,“bN”,bN); Copy c = b.Find (“Copy”,“avail”,true); Copy c = b.Find (“Copy”,“avail”,true); User u = lib.Find(“User”,“uId”,uId); User u = lib.Find(“User”,“uId”,uId); u.Add(“Copy”,c); c.Set(“avail”,false); return c; } Compiler asks for information or determines it by rules

class Library { Copy CheckOut (Library lib,BookName bN, UserId uId){ Book b = cg.Find(lib,“to Book”,“bN”,bN); Copy c = cg.Find (b,“to Copy”,“avail”,true); Copy c = cg.Find (b,“to Copy”,“avail”,true); User u = cg.Find(lib,“to User”,“uId”,uId); User u = cg.Find(lib,“to User”,“uId”,uId); cg.Add(u,“to Copy”,c); cg.Set(c,“to Boolean”,”avail”,false); return c; } For DJ

Doug’s proposal Book b = cg.fetch( lib, new Strategy (“to Book”), new Predicate() { boolean match(Object obj){ return((Book) obj).get_isbn() == 678); } ) Instead of: Book b = cg.Find(lib,“to Book”,“isbn”,678);

Doug’s proposal Book b = cg.fetch( lib, new Strategy (“to Book”), new Predicate() { boolean match(Object obj){ return((Book) obj).get_isbn() == 678); } ) Instead of: Book b = cg.Find(lib,“to Book”,“isbn”,678); interface Predicate { boolean match(Object); } Anonymous object of anonymous class More flexible but more verbose

Book b = cg.Find(lib,“to Book”,“bN”,bN); Copy c = cg.Find (b,“to Copy”,“avail”,true); Copy c = cg.Find (b,“to Copy”,“avail”,true); User u = cg.Find(lib,“to User”,“uId”,uId); User u = cg.Find(lib,“to User”,“uId”,uId); cg.Add(u,“to Copy”,c); “avail”,true Copy cg.Delete(u,“to Copy”, “avail”,true); cg.Set(c,“to Boolean”,”avail”,false); Boolean cg.Get(c,“to Boolean”,”avail”); int cg.Traverse(company,”to Salary”,v); For DJ/paper

0..*, 1..*: Book b = cg.Find(lib,“to Book”,“bN”,bN); cg.Add(u,“to Copy”,c); “avail”,true cg.Delete(u,“to Copy”, “avail”,true); cg.Traverse(company,”to Salary”,v); cg.Gather(company,”to Salary”); 0..1, 1..1 cg.Set(c,“to Boolean”,”avail”,false); cg.Get(c,“to Boolean”,”avail”); For DJ/paper/constraints

0..*, 1..*: Book cg.Find(lib,“to Book”,“bN”,bN); Find in library lib a book with data member “bN” = bN. void cg.Add(u,“to Copy”,c); Add to user u a copy c “avail”,true Copy cg.Delete(u,“to Copy”, “avail”,true); Delete from user u a copy with avail == true For DJ/paper/constraints

0..*, 1..*: int cg.Traverse(company,”to Salary”,v); traverse from company to Salary and perform visiting actions of v. Vector cg.Gather(company,”to Salary”); collect all Salary-objects reachable from company 0..1, 1..1 Boolean cg.Set(c,“to Boolean”,”avail”,false); Boolean cg.Get(c,“to Boolean”,”avail”); For DJ/paper/constraints

CheckOut { )-> Book Find(this.bN==bN)-> Book Find(avail==true)-> Find(avail==true)->Copy; Find(this.uId==uId)-> User; addCopy { u:User Add(c)-> Copy; } Aspect Language: don’t use

CheckOut (lib,bN,uId){ lib:Library( )-> Book Find(this.bN==bN)-> Book Find(avail==true)-> Find(avail==true)-> c:Copy; Find(this.uId==uId)-> u:User;) addCopy { only one choice u:User Add(c)-> Copy; c:Copy Set(avail,false)-> Boolean } Compiler asks for information or determines it by rules Definition: an interaction schema is a sequence of navigation statements of the form o1:T1 -Action1-> o2:T2 -Action2-> o3:T3...

Advantages High-level description of behavior in terms of an ideal UML class diagram Behavior can be adapted to many concrete class diagrams –Some details of action parameters may be filled in under compiler control

Generalized Traversals Library Find-> Book Traversal from Library to Book must have upper cardinality > 1, e.g., 0..*, 1..*. Compiler will ask for properties to select a book. Rule: if an object of the class of a data member of Book is available, it will choose that one as default

Generalized traversals lib:Library Find-> b:Book DJ: Book b = cg.Find(lib, new Strategy(“from Library to Book”), “property bN”,bookName); Book b = cg.Find(lib, new Strategy(“from Library to Book”), “property isbn”,isbnNumber);

Connection actions/class graph lib:Library Find-> b:Book u:User Add(c)-> Copy lib:Library Delete-> b:Book 0..*, 1..*

Connection actions/class graph c:Copy Set(avail,false)-> Boolean c:Copy Get(avail)-> b:Boolean == c:Copy Fetch(avail)-> b:Boolean 1..1, traverse a little different c:Company Traverse(v1)-> r:Result traverses to all classes mentioned in v1 and performs visiting action. There must be a path to each such class?

Generalized traversals lib:Library Find-> b:Book DJ: Book b = cg.Find(lib, new Strategy(“from Library to Book”), “property author”,authorName); Find is like a generalized fetch

Generalized traversals u:User Add(c)-> Copy; cg.Add(u,new Strategy (“from User to Copy”), c); Expects a unique path from User to Copy that is “insertable” and it adds c at end. Insertable means...

New Operations for DJ Find, Delete, Add Set, Get=Fetch Traverse, Gather c:Copy Set(avail,false)-> Boolean cg.Set(c, new Strategy( “from Copy through -> *,avail,* to Boolean”), false);

DJ: dealing with vectors How can DJ deal with Java vectors and other collection classes? A = B C. //from A via B to C B = Vector. R = Q. Q = C. S = T. T =.

DJ: dealing with vectors A = B C. //from A via B to C B = Vector. R = Q. Q = C. S = T. T =. A B C Vector R Q S T

DJ: dealing with vectors A = B C. //from A via B to C B = Vector. R = Q. Q = C. S = T. T =. A B C Vector R Q S T

Dealing with Vector Enlarge the class graph by drawing a subclass edge from Vector to every node. Might create many edges Use the generality of the strategy compilation algorithm

Parametric types Essential for code reuse program fragment viewed in different ways intersection/union types derived automatically: analysis principal type: expect less for free variables, more for result

Subtraversal s as argument s.apply(“a”);