Presentation is loading. Please wait.

Presentation is loading. Please wait.

TOOLS USA '99 Interaction Schemata: Compiling Interactions to Code Neeraj Sangal, Edward Farrell, Tendril Software, Inc, Westford, MA

Similar presentations


Presentation on theme: "TOOLS USA '99 Interaction Schemata: Compiling Interactions to Code Neeraj Sangal, Edward Farrell, Tendril Software, Inc, Westford, MA"— Presentation transcript:

1 TOOLS USA '99 Interaction Schemata: Compiling Interactions to Code Neeraj Sangal, Edward Farrell, Tendril Software, Inc, Westford, MA http://www.tendril.com Karl Lieberherr, and David H. Lorenz College of Computer Science Northeastern University Boston, MA 02115

2 Northeastern University Outline oMotivation  Generate Code From Interaction Diagrams oThe Problem  Diagrams are not precise oConcept Formulization  Interaction Schemata oTwo Implementation Approaches  Code generation approach  Structure Builder (SB)  Generative approach  DJ (Demeter Java)

3 Northeastern University Motivation: Round Trip

4 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

5 Northeastern University The Problem oProblem  UML interaction diagrams are not precise enough to prescribe code.  UML interaction diagrams are difficult to keep up-to-date with the code. oSolution 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

6 Northeastern University What's Missing in Interaction Diagrams oNo object "book-keeping" oIgnores scope and visibility issues oIgnores object transportation issues oOther details: method parameters, return types, collections to iterate over, etc. *Sub-Goal: Make Interaction Diagrams Complete Code Generation Approach: Structure Builder (SB) Generative Approach: DJ (Demeter Java) and then or

7 Northeastern University Association Role Class Example: Library System Cardinality

8 Northeastern University Where did user come from? Object "Book-Keeping" oLibrary.checkIn(Copy copy, UID uid) What is the signature of removeCopy ? *Generated methods must have correct signature and return type.

9 Northeastern University What is the scope of book ? Scope and Visibility book is out of scope! *Objects have scope even in Interaction Diagrams

10 Northeastern University Where did copy come from? Downward Object Transportation  copy must be transported down through removeCopy() Returned by findCopy() Used by release()

11 Northeastern University Where did resUser come from? Upward Object Transportation Generated by getFirstOnReservationList() Called for notifyBookReady()  resUser must be transported up through getNextUser()

12 Northeastern University Object Transportation - Wrapper firstUser and secondUser have to be transported up through getNextUser() *Second object is passed back through a wrapper.

13 Northeastern University Textual Representation oNested Methods a.m1() { b.m2() } oConditional if (test) { a.m1(); }

14 Northeastern University Formalization of Actions oSyntax for actions  [ interactor  interactor ... ]. actionName ( exp1, exp2,... ) return( type1 retexp1, type2 retexp2,... ) {... } oBasic actions  Method call  Conditional  Iteration oAdditional predefined actions on collections  Find  Add  Remove oUser defined actions  Anything Can contain other actions The scope of each returned variable is limited to being inside the innermost enclosing conditional or iterative action.

15 Northeastern University Sequence Diagram for CheckIn

16 Northeastern University Interaction Schema for CheckIn Library.checkIn(UID uid, Copy copyId) { [library  users  uid]. find (uid'current == uid) return (User users'current as theUser) [theUser  borrows  copyId]. remove (copyId'current == copyId) return (Copy borrows'current as theCopy) [theCopy].getBook() return (Book book as theBook) [theBook  reserves]. remove (reserves'index == 0) return (User reserves'current as theReserver) if (theReserver != null) { [theReserver  holds]. add (theCopy) [theReserver]. notify (theCopy); } }

17 Northeastern University Interactions Involve Multiple Classes C1 C2 C3 C4 C5 Interact-1 Interact-2Interact-3 Interact-4 C1 C2 C3 C4 C5

18 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 oFour methods generated in three classes  Library  User  Book

19 Northeastern University StructureBuilder Approach: Generated Method Dialog Actions Action Properties Available Objects Action on Selected Object

20 Northeastern University Object Transportation firstUser.notifyBookReady() is missing information: red color indicates a problem

21 Northeastern University Object Transportation User links the missing information: firstUser

22 Northeastern University DJ Approach oBuild on Demeter/Java experience  AP Library, visitor organization  Create class graph from Java programs  Generalized traversals: find, add,... oName traversals  new TravSpec(" From Library to User ").container(this)); oCompute traversals dynamically  Container c = new TraversalGraph(Main.classGraph, new TravSpec(…)); oMain 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.

23 Northeastern University The checkIn Method in DJ void 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); } }

24 Northeastern University Conclusions oPossible to generate code from interaction diagrams.  Interactions must be made complete.  Possible to preserve simplicity of interaction diagrams and yet make them complete. oInteraction diagrams can be made adaptive by addition of traversal semantics. oActions allow programmers to try out different types of data structures in a structure-shy manner. oDiagrams like programs need to deal with basic programming issues like scope, visibility, and transportation.

25 Northeastern University Future oCombine the two approaches. oDomain specific action types. oImproved object caching techniques. oSuggestions for changes to internal data structures for improved performance.

26 Northeastern University Additional Information oStructureBuilder @ Tendtril Software  Free product evaluation download  www.tendril.com oDJ @ Northeastern University  Download papers and source code  www.ccs.neu.edu/research/demeter

27 The End

28 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 firstUser return (firstUser); }

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


Download ppt "TOOLS USA '99 Interaction Schemata: Compiling Interactions to Code Neeraj Sangal, Edward Farrell, Tendril Software, Inc, Westford, MA"

Similar presentations


Ads by Google