TOOLS USA '99 Interaction Schemata: Compiling Interactions to Code Neeraj Sangal, Edward Farrell,...
-
Upload
david-ferguson -
Category
Documents
-
view
216 -
download
2
Transcript of TOOLS USA '99 Interaction Schemata: Compiling Interactions to Code Neeraj Sangal, Edward Farrell,...
TOOLS USA '99
Interaction Schemata:Compiling Interactions to Code
Neeraj Sangal, Edward Farrell,Tendril Software, Inc,
Westford, MAhttp://www.tendril.com
Karl Lieberherr, and David H. LorenzCollege of Computer Science
Northeastern UniversityBoston, MA 02115
Northeastern University
Outline Motivation
Generate Code From Interaction Diagrams
The Problem Diagrams are not precise
Concept Formulization Interaction Schemata
Two Implementation Approaches Code generation approach
Structure Builder (SB) Generative approach
DJ (Demeter Java)
Northeastern University
Motivation: Round Trip
Northeastern University
Interactions Diagrams
// Class: Library// File: Library.java/** * (c) Northeastern University * @param book * @author dl * @SBGen Generated Method (2) */void upwardTransportationExample(Book book) {// SBgen: Calls generated method on Book (2)SBObject sbsecondUser = new SBObject();User firstUser = book.getNextUser(sbsecondUser);User secondUser = (User)sbsecondUser.getValue();// SBgen: End Call
// SBgen: Action Execute method on User (5)firstUser.notifyBookReady();
// SBgen: Action Execute method on User (6)secondUser.alertYouAreNext();}
// Class: Book// File: Book.java/** @SBGen Generated Method (4), created by Library.up(Book) (Library.2,-2) */User getNextUser(SBObject sbsecondUser) {// SBgen: Action Execute method on Book (3)User firstUser = getFirstUser();// SBgen: Action Execute method on Book (4)
Goal: Generating Code From Interaction Diagrams
Goal: Generating Code From Interaction Diagrams
Northeastern University
The Problem Problem
UML interaction diagrams are not precise enough to prescribe code.
UML interaction diagrams are difficult to keep up-to-date with the code.
Solution Approaches Code generation approach
Structure Builder: A Java design tool Method generated with mark-ups
Generic approach DJ: A research project Interactive traversals using JGL and Reflection
Northeastern University
What's Missing in Interaction Diagrams
No object "book-keeping" Ignores scope and visibility issues Ignores object transportation issues Other details: method parameters, return types,
collections to iterate over, etc.
Sub-Goal: Make Interaction Diagrams Complete
Sub-Goal: Make Interaction Diagrams Complete
Code Generation Approach:
Structure Builder (SB)
Generative Approach:
DJ (Demeter Java)
and then
or
Northeastern University
Association
Role
Class
Example: Library System
Cardinality
Northeastern University
Where did user come from?
Object "Book-Keeping" Library.checkIn(Copy copy, UID uid)
What is the signature of removeCopy?
Generated methods must have correct signature and return type.
Generated methods must have correct signature and return type.
Northeastern University
What is the scope of book?
Scope and Visibility
book is out of scope!
Objects have scope even in Interaction Diagrams
Objects have scope even in Interaction Diagrams
Northeastern University
Where did copy come from?
Downward Object Transportation
copy must be transported down through removeCopy()
copy must be transported down through removeCopy()
Returned by findCopy()
Used by release()
Northeastern University
Where did resUser come from?
Upward Object Transportation
Generated by getFirstOnReservationList()
Called for notifyBookReady()
resUser must be transported up through getNextUser()
resUser must be transported up through getNextUser()
Northeastern University
Object Transportation - Wrapper
firstUser and secondUser have to be transported up through getNextUser()
Second object is passed back through a wrapper.
Second object is passed back through a wrapper.
Northeastern University
Textual Representation Nested Methods
a.m1() {b.m2()
}
Conditional
if (test) {a.m1();
}
Northeastern University
Formalization of Actions Syntax for actions
[interactor interactor ...].actionName(exp1,exp2,...) return(type1 retexp1, type2 retexp2,...) {...}
Basic actions Method call
Conditional
Iteration
Additional predefined actions on collections Find
Add
Remove
User defined actions Anything
Can contain other actionsThe scope of each returned
variable is limited to being inside the innermost enclosing conditional or iterative action.
Northeastern University
Sequence Diagram for CheckIn
Northeastern University
Interaction Schema for CheckInLibrary.checkIn(UID uid, Copy copyId) { [libraryusersuid].find(uid'current == uid) return (User users'current as theUser)
[theUserborrowscopyId].remove(copyId'current == copyId) return (Copy borrows'current as theCopy)
[theCopy].getBook() return (Book book as theBook)
[theBookreserves].remove(reserves'index == 0) return (User reserves'current as theReserver)
if (theReserver != null) { [theReserverholds].add(theCopy)
[theReserver].notify(theCopy); }}
Northeastern University
Interactions Involve Multiple Classes
C1
C2 C3
C4
C5
Interact-1
Interact-2 Interact-3Interact-4
C1
C2 C3
C4
C5
Northeastern University
void checkIn(UID uid, Copy copyId){ User user = null; Object tmpKey; Enumeration i = users.keys(); while(i.hasMoreElements()) { tmpKey = i.nextElement(); user = (User)users.get(tmpKey); if (user.uid==uid) break; } Copy copy = user.checkIn(copyId); Book book = copy.getBook(); User resUser = book.checkIn(); if (resUser != null) { resUser.checkIn0(copy); resUser.notify(copy); }}
User checkIn(){ User resUser = null; int size = reserves.size(); if (size > 0) { resUser = reserves.elementAt(0); reserves.removeElementAt(0); }
return resUser;}
Copy checkIn(Copy copyId){ Copy copy = null; int i, size = borrows.size(); for (i=size-1; i>=0; i--) { Copy tmpVar = (Copy)borrows.elementAt(i); if (tmpVar.getId() == copyId) { copy = tmpVar; borrows.removeElementAt(i); break; } return copy; }
void checkIn0(Copy copy){ holds.addElement(copy);}
Method generated in class Library
class User
class Book
Method Generation Approach Four methods generated in
three classes Library User Book
Northeastern University
StructureBuilder Approach: Generated Method Dialog
Actions
Action Properties
Available Objects
Action on Selected Object
Northeastern University
Object Transportation
firstUser.notifyBookReady()is missing information: red color indicates a problem
Northeastern University
Object Transportation
User links the missing information: firstUser
Northeastern University
DJ Approach Build on Demeter/Java experience
AP Library, visitor organization Create class graph from Java programs Generalized traversals: find, add, ...
Name traversals new TravSpec("From Library to User").container(this));
Compute traversals dynamically Container c = new TraversalGraph(Main.classGraph,
new TravSpec(…));
Main observation Actions like add, find, and delete appear in Generic Programming
(GP) as methods of container interfaces (e.g., JGL). DJ attempts to reuse those generic algorithms.
Better to have an easy-to-use less-powerful
system than a harder-to-use more-powerful
system.
Northeastern University
The checkIn Method in DJvoid checkIn(UID uid, Copy copyId){
Container LibraryToUserContainer = new TraversalGraph( Main.classGraph, new TravSpec("From Library to User").container(this));User user = Finding.findIf( LibraryToUserContainer, new FieldEquals("uid",uid));if (user == null) return;Container UserToCopyContainer = new TraversalGraph( Main.classGraph, new TravSpec("From User through borrows to Copy").container(user));Copy copy = Finding.findIf( UserToCopyContainer, new FieldEquals("copyId",copyId));if (copy == null) return;Removing.remove(UserToCopyContainer,copy);Container CopyToUser = new TraversalGraph (…) ;Container UserToCopyHoldsCont = new TraversalGraph( Main.classGraph, new TravSpec("From User through holds to Copy").container(user));User reserver = (User)CopyToUser.remove(CopyToUser.elements());if (reserver != null) {
UserToCopyHoldsCont.add(copy);reserver.notify(copy);
}}
Northeastern University
Conclusions Possible to generate code from interaction diagrams.
Interactions must be made complete. Possible to preserve simplicity of interaction diagrams and
yet make them complete.
Interaction diagrams can be made adaptive by addition of traversal semantics.
Actions allow programmers to try out different types of data structures in a structure-shy manner.
Diagrams like programs need to deal with basic programming issues like scope, visibility, and transportation.
Northeastern University
Future Combine the two approaches. Domain specific action types. Improved object caching techniques. Suggestions for changes to internal data structures for
improved performance.
Northeastern University
Additional Information StructureBuilder @ Tendtril Software
Free product evaluation download www.tendril.com
DJ @ Northeastern University Download papers and source code www.ccs.neu.edu/research/demeter
The End
Northeastern University
Code for Transporting One Object Up
// Class: Library// File: Library.java/** * (c) Northeastern University * @param book * @author dl * @SBGen Generated Method (2) */void up(Book book) {
// Call generated method on Book (2)User firstUser = book.getNextUser();// Action Execute method on User (5)firstUser.notifyBookReady();
}
// Class: Book// File: Book.java/** @SBGen Generated Method (4) */User getNextUser() {
// Action Execute method on Book (3)User firstUser = getFirstUser();// Return firstUserreturn (firstUser);
}
Northeastern University
Generated Code for Upward Transportation of Two Objects
// Class: Library
// File: Library.java
/**
* (c) Northeastern University
* @param book
* @author David Lorenz
* @SBGen Generated Method (2)
*/
void upwardTransportationExample(Book book) {
// SBgen: Calls generated method on Book (2)
SBObject sbsecondUser = new SBObject();
User firstUser = book.getNextUser(sbsecondUser);
User secondUser = (User)sbsecondUser.getValue();
// SBgen: End Call
// SBgen: Action Execute method on User (5)
firstUser.notifyBookReady();
// SBgen: Action Execute method on User (6)
secondUser.alertYouAreNext();
}
// Class: Book
// File: Book.java
/** @SBGen Generated Method (4), created by Library.up(Book) (Library.2,-2) */
User getNextUser(SBObject sbsecondUser) {
// SBgen: Action Execute method on Book (3)
User firstUser = getFirstUser();
// SBgen: Action Execute method on Book (4)
User secondUser = getSecondUser;
// SBgen: Returns firstUser
sbsecondUser.setValue(secondUser);
return firstUser;
// SBgen: End Return
}