SERA 2013 (August 7, 2013 in Prague, Czech Republic)

33
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] [email protected] http:/ /umple.org Improving Code Generation for Associations 1

description

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] [email protected] http:/ /umple.org. - PowerPoint PPT Presentation

Transcript of SERA 2013 (August 7, 2013 in Prague, Czech Republic)

Page 1: 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

Page 2: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

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

Page 3: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

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

Page 4: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

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.

Page 5: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

Available Multiplicities

5

Impr

ovin

g Co

de G

ener

ation

for A

ssoc

iatio

ns

Optional One / OneMany / Star

Page 6: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

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

Page 7: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

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

Page 8: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

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

Page 9: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

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

Page 10: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

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

Page 11: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

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

Page 12: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

Multiplicity Rankings inExample / Textbook Models

12

Impr

ovin

g Co

de G

ener

ation

for A

ssoc

iatio

ns

Page 13: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

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

Page 14: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

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

Page 15: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

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

Page 16: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

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

Page 17: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

One Association-End

17

Impr

ovin

g Co

de G

ener

ation

for A

ssoc

iatio

ns

Page 18: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

Many Association-End

18

Impr

ovin

g Co

de G

ener

ation

for A

ssoc

iatio

ns

Page 19: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

Try For Yourself

19

Impr

ovin

g Co

de G

ener

ation

for A

ssoc

iatio

ns

http://try.umple.org

Page 20: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

Academic Use Of Umple

20

Impr

ovin

g Co

de G

ener

ation

for A

ssoc

iatio

ns

Page 21: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

Umple (metamodel.umple.org)

21

Impr

ovin

g Co

de G

ener

ation

for A

ssoc

iatio

ns

Page 22: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

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

Page 23: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

Industry Examples

23

Impr

ovin

g Co

de G

ener

ation

for A

ssoc

iatio

ns

Page 24: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

hatchmortgage.com

24

Impr

ovin

g Co

de G

ener

ation

for A

ssoc

iatio

ns

Page 25: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

alms.arrowmight.ca

25

Impr

ovin

g Co

de G

ener

ation

for A

ssoc

iatio

ns

Page 26: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

arm.arrowmight.ca

26

Impr

ovin

g Co

de G

ener

ation

for A

ssoc

iatio

ns

Page 27: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

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

Page 28: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

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&notext&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

Page 29: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

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

Page 30: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

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

obahy
getting involved should be about using Umple or contributing to Umple. See the same slide in the other presentation
Page 31: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

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

Page 32: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

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

Page 33: SERA 2013  (August 7, 2013  in Prague, Czech  Republic)

33

Impr

ovin

g Co

de G

ener

ation

for A

ssoc

iatio

ns