SERA 2013 (August 7, 2013 in Prague, Czech Republic)
description
Transcript of SERA 2013 (August 7, 2013 in Prague, Czech Republic)
Improving Code Generation for Associations: Enforcing Multiplicity Constraints and Ensuring Referential Integrity
SERA 2013 (August 7, 2013 in Prague, Czech Republic)
Omar Badreddin, Andrew Forward, Timothy C. Lethbridge1 University of Ottawa
[email protected] / [email protected] [email protected] / [email protected]@site.uottawa.cahttp://umple.org
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
1
Overview• Umple Philosophy (Quick Review)• Umple Association Syntax• Umple in Academia and Industry• Getting Involved• Future Work
2
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
Umple Philosophy
3
Umple features can be created and viewed diagrammatically or textually
Umple extends a base language in a minimally invasive way
Intermediate generated code should not be edited
=Modeling is programming and vice versa
No round-trip engineering required
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
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
4
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
class X { 0..1 -- * Y;}class Y {}
X can have many Y’s, and Y can optionally have one X.
Available Multiplicities
5
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
Optional One / OneMany / Star
Umple Association Syntax
// Embed within the classclass X{ 0..1 -- * Y yonks;}
class Y {}
// Or Define explicitlyclass Z {}association m { * Z -> * Y; } 6
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
Supports all multiplicities,e.g. 1, m..n, 1..*
To name an association (also optional) simply declare it explicitly as shown here.
Optionally name the association end for clearer intention as well as to support multiple associations between two classes.
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 yy.setX(x2); // x1 unassociated with y
7
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
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)
8
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
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
9
Expl
orin
g a
Mod
el-O
rient
ed a
nd E
xecu
tabl
e Sy
ntax
for U
ML
Attrib
utes
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
10
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
Multiplicity Rankings inIndustrial Models
11
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
One To Many Most Used In All Sources
Very few non one or many ends
Multiplicity Rankings inExample / Textbook Models
12
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
Multiplicity Rankings inUML Repositories
13
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
UML Repository viewable at http://try.umple.org
Code Generation for Associations in Existing Tools
14
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
• 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
15
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
Bi-Directional Associations (between different classes)
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)
A total 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
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
16
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
class X { 0..1 -- * Y;}class Y {}
One Association-End
17
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
Many Association-End
18
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
Try For Yourself
19
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
http://try.umple.org
Academic Use Of Umple
20
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
Umple (metamodel.umple.org)
21
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
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)
22
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
Industry Examples
23
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
hatchmortgage.com
24
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
alms.arrowmight.ca
25
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
arm.arrowmight.ca
26
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
http://cruise.eecs.uottawa.ca/umpleonline/iframeexample.html
Embed Models In HTML
27
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
28
<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>
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
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
29
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
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: [email protected]
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
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
31
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
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
32
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns
33
Impr
ovin
g Co
de G
ener
ation
for A
ssoc
iatio
ns