330 likes | 433 Views
SERA 2013 (August 7, 2013 in Prague, Czech Republic) Omar Badreddin, Andrew Forward, Timothy C. Lethbridge1 University of Ottawa obadr024@uottawa.ca / oobahy@gmail.com aforward@site.uottawa.ca / aforward@gmail.com tcl@site.uottawa.ca http:/ /umple.org.
E N D
SERA 2013 (August 7, 2013 in Prague, Czech Republic) Omar Badreddin, Andrew Forward, Timothy C. Lethbridge1 University of Ottawa obadr024@uottawa.ca / oobahy@gmail.com aforward@site.uottawa.ca / aforward@gmail.com tcl@site.uottawa.ca http://umple.org Improving Code Generation for Associations: Enforcing Multiplicity Constraints and Ensuring Referential Integrity
Overview Umple Philosophy (Quick Review) Umple Association Syntax Umplein Academia and Industry Getting Involved Future Work
Umple Philosophy Improving Code Generation for Associations Umple extends a base language in a minimally invasive way Umple features can be created and viewed diagrammatically or textually = Modeling is programming and vice versa Intermediate generated code should not be edited No round-trip engineering required
Defining Association • Specification describing the links between objects that can exist at run time • Each end of the association has a multiplicity • Specifies upper and lower bound on the number of links Improving Code Generation for Associations class X { 0..1 -- * Y; } class Y {} X can have many Y’s, and Y can optionally have one X.
Available Multiplicities Optional One / One Many / Star Improving Code Generation for Associations
Umple Association Syntax // Embed within the class class X { 0..1 -- *Y yonks; } class Y {} // Or Define explicitly class Z {} associationm { * Z -> * Y; } Supports all multiplicities, e.g. 1, m..n, 1..* Optionally name the association end for clearer intention as well as to support multiple associations between two classes. To name an association (also optional) simply declare it explicitly as shown here. Directed associations
Referential Integrity Either side of the relationship can be set, and the other will automatically be maintained, so x.addY(y) equivalent to y.setX(x) If either side removes a relationship, then the other side will automatically be removed as well, so y.setX(x1); // x1 associated with y y.setX(x2); // x1 unassociated with y
Multiplicity Constraint Set / Add / Remove might fail (returns a false) if the multiplicity is not supported Multiplicities also affect relationship (e.g. setting Y to a new X, removes the old relationship because of the 0..1 multiplicity)
Associations In Practice Too difficult to identify associations with any degree of certainty by looking only at the source code Difficulty with which we had trying to identify the use of association in code served as a motivation in itself
Analyzed Models Instead • 1400 Industry examples by looking at UML specs and UML profiles • UML v1.5 • UML v2.1.2 • MARTE, Flow Composition, ECA, Java, Patterns, rCOS • 98 Example models from a course textbook of one of the authors • 250 Repository models from the collection of models codified in Umple
Multiplicity Rankings inIndustrial Models Improving Code Generation for Associations One To Many Most Used In All Sources Very few non one or many ends
Multiplicity Rankings inExample / Textbook Models Improving Code Generation for Associations
Multiplicity Rankings inUML Repositories Improving Code Generation for Associations UML Repository viewable at http://try.umple.org
Code Generation for Associations in Existing Tools Improving Code Generation for Associations • All similar implementations, member variables for One multiplicities and List variables for Many • Little to no referential integrity • Little to no multiplicity constraints
Association Combinations Bi-Directional Associations (between different classes) • Atotal of 42 different possible association types have been identified • 28 for bidirectional associations • 7 for unidirectional associations • 7 for symmetric associations • Each case explicitly handled, with code re-use where possible Improving Code Generation for Associations • Directed Associations * -> 0..1; -> 1; -> *; -> m..n; -> n; -> m..*; -> 0..n Symmetric Associations (between the same class) • Reads the same in both directions (e.g. spouse)
Association Code Generation • Member variables for One • List variables for Many • Referential Integrity maintained • E.g. a student switches mentors • Multiplicity Constraints enforced • E.g. cannot overload a mentor class X { 0..1 -- * Y; } class Y {}
Try For Yourself http://try.umple.org
Improving Code Generation for Associations Academic Use Of Umple
Umple(metamodel.umple.org) Improving Code Generation for Associations
Teaching Umple • University of Ottawa, Canada • Second year Introduction to Software Engineering • Fourth year Advanced Design • Other professors, including at graduate level • SCORE finalists at ICSE 2011 • UCOSP (Undergraduate Capstone Open Source Project) Improving Code Generation for Associations
Improving Code Generation for Associations Industry Examples
hatchmortgage.com Improving Code Generation for Associations
alms.arrowmight.ca Improving Code Generation for Associations
arm.arrowmight.ca Improving Code Generation for Associations
Improving Code Generation for Associations Embed Models In HTML http://cruise.eecs.uottawa.ca/umpleonline/iframeexample.html
<html> <head><title>My Example</title></head> <body> <p> <iframe height=550 width=100% frameborder="0" scrolling="auto" src="http://try.umple.org/umple.php?example=2DShapes&readOnly¬ext&nomenu&nochrome"><p>No iframe support</p></iframe> </p> <p> <iframe height=550 width=100% frameborder="0" scrolling="auto" src="http://try.umple.org/umple.php?example=2DShapes&readOnly&nodiagram&nomenu&nochrome"><p>No iframe support</p></iframe> </p> </body> </html> Improving Code Generation for Associations
Current and Future Work • Umplification • Starting with OO code, incrementally add modeling abstractions • Maintain system functionality throughout the process • Using existing code repositories • Reduce code size • Model Based Tracing • Define tracing directive at the model level • Aspect Orientation • Additional Refactoring on Umple itself Improving Code Generation for Associations
Getting Involved • Open source project: https://code.google.com/p/umple/ • Teaching • Use Umple to introduce UML and MDE. • Umplification • Incrementally replace boilerplate code with modeling abstractions • Lightweight Modeling and Analysis • Visualize Umple source as UML diagrams to analyze it • Model driven development • Generate code in one of the supported base languages • Rapid system prototyping Comments and feedback: tcl@site.uottawa.ca Improving Code Generation for Associations
More information Publications on Umple: https://code.google.com/p/umple/wiki/Publications The User Manual: http://cruise.eecs.uottawa.ca/umple/GettingStarted.html Umple Home page: http://cruise.eecs.uottawa.ca/umple/ Download Umple: http://cruise.eecs.uottawa.ca/umpleonline/download_eclipse_umple_plugin.html Report an issue: https://code.google.com/p/umple/issues/entry
Summary • 42 unique ways to define an association between one or two • In practice, mostly One or Many, but mostly does not mean always • Implemented referential integrity and multiplicity constraints for each unique combination • Test-Driven approach to reduce regressions • Important as new features are added to the languagethe help reduce code clones • Many additional features available in Umple including tracing, state machines, code injections, mixin • More coming including better support for aspect orientation