DevEX - reference for building teams, processes, and platforms
Extension and Evolution
1. Extension and Evolution
IN4308
Model-Driven Software Development
Lecture 12
Eelco Visser
Software Engineering Research Group
Delft University of Technology
Netherlands
May 25, 2010
2. Conventional Software Development
'model'
'model' GPL
GPL 'machine'
'machine'
code
code compile
compile
'design'
'design' program
program code
code
3. Conventional Software Maintenance
understand
understand
'model'
'model' GPL
GPL 'machine'
'machine'
compile
compile
'design'
'design' program
program code
code
modify
modify
abstractions encoded in program
maintenance at low level of abstraction
4. Model-Driven Software Development
DSL
DSL GPL
GPL 'machine'
'machine'
program
program generate
generate compile
compile
program
program code
code
(model)
(model)
raise the level of abstraction to a technical or application domain
automatically generate implementation code from model
5. Model-Driven Software Evolution
modify
modify
maintenance on models instead of implementation
implementation regenerated after modification of models
10. Portability
C#
C#
dsl-to-csharp
dsl-to-csharp
dsl-to-java
dsl-to-java
Java
Java
abstract over the target domain
generate code for multiple platforms from same model
11. Code Quality
does generator produce robust and correct code?
are errors detected early in the translation pipeline?
model verification is preferable over debugging target code
16. Program Equivalence
Two programs are the same if they have the same
- behaviour
- userinterface
- effects on the database
- performance
What is the meaning of 'same'?
Abstract over non-important differences
Implementation details
(e.g. order of statements does not always matter)
Look and feel
17. Reasons for Lack of Coverage
Completeness
only part of the domain is covered
Example: domain model vs business logic
80/20 rule : generate 80%, write 20%
Tuning
the generated code is not exactly what is desired
18. Customization of Generated Code
modify
not all customizations can be realized in models
generated code may need to be adapted
19. Scaffolding (aka Fill in the Blanks)
incomplete code generation produces programs with holes
to be filled in by developer
20. Scaffolding (aka Fill in the Blanks)
Publication
Publication
title :: String
title String
authors →→ List<Author>
authors List<Author>
journal →→ Journal
journal Journal public class Publication {{
public class Publication
Private String _title;
Private String _title;
Public String getTitle() {{
Public String getTitle()
citation() :: String Return _title;
Return _title;
citation() String }}
Public void setTitle(x :: String) {{
Public void setTitle(x String)
_title := x;
_title := x;
}}
…… getters, setters for authors,
getters, setters for authors,
journal ……
journal
Public String citation() {{
Public String citation()
// fill in code
// fill in code
}}
'boilerplate code' is generated
'business methods' should be }}
filled in by developer
21. Scaffolding Breaks Evolution
modify
modify
modify
modify ?? ?
?
if model and code are modified, how do we merge the results?
22. Protected Regions
modify
modify
modify copy
modify copy
modify copy
modify copy
generator preserves 'protected regions'
does not support unanticipated tuning
breaks generator encapsulation by exposing implementation
23. Protected Regions
public void openUserScreenShowPersons() {
ShowPersonsScreenComposite showPersonsScreen =
new ShowPersonsScreenComposite(mainController.getShowPerso
.getScreenPar
this);
/*PROTECTED REGION ID(ShowPersons_game_behavior_usecases_perso
showPersonsScreen.personList.add("Marcy");
showPersonsScreen.personList.add("Freddy");
showPersonsScreen.personList.add("Mary-Anne");
/*PROTECTED REGION END*/
mainController.getShowPersonsScreenContainer()
.showScreen(showPersonsScreen);
// next step called by gui to transition...() method
}
public void systemCallEnd() {
/*PROTECTED REGION ID(systemCall_game_behavior_usecases_perso
// TODO: perform activity
mainController.getShowPersonsScreenContainer().getShell().clo
/*PROTECTED REGION END*/
}
Source: http://public.tfh-berlin.de/~petrasch/uploads/media/TU_MDAPetrasch_110907.pdf
24. Roundtrip Engineering
modify
modify
extract model from modified code
can changes to code be reflected in model?
implies lack of abstraction
25. Roundtrip Engineering
modify
modify
modify
modify
preserve?
preserve?
Make changes to model and code
can changes to code be reflected in model?
implies model/code bijection
26. Tuning Generated Code
"entity" Id ":" Id "{" Property* Function* "}"
-> Entity {cons("Entity")}
Entity -- KW["entity"] _1 KW[":"] _2 KW["{"] _3 _4 KW["}"]
Entity -- V[V is=2[H[KW["entity"] _1 KW[":"] _2 KW["{"]]
_3 _4]
KW["}"]]
default pretty-print rules can be generated; tuning needed to get it right
general: skeleton for user interface from data model need tuning
27. Customization 'From the Outside'
customization should never require direct modification of generated code
customization code must modify/interact with generated code
what is the interface? avoid exposing generation scheme
28. Customization with Partial Classes
inputs
partial class extends generated class without modifying generated files
29. Customization with Partial Classes
public partial class Publication { {
public partial class Publication
entity Publication { { ////generated code; don't change
generated code; don't change
entity Publication
Author → Author private Author _author;
private Author _author;
Author → Author
… public Author getAuthor () { {
public Author getAuthor ()
…
}} return _author;
return _author;
}}
}}
public partial class Publication { {
public partial class Publication
public String citation() { {...
public String citation() ...
if(this.getAuthor() != null) { {
if(this.getAuthor() != null)
cc:= cc++getAuthor().getName()
:= getAuthor().getName()
}}
...
...
}}
}}
35. Built-in Types
aa::::AA
f(x.a)
f(x.a)
class Aimpl { {
class Aimpl
f() {…}
f() {…}
}}
Aimpl a;
Aimpl a;
x.a.f()
x.a.f()
make external code available through type abstraction to model
built-in types capture domain-specific functionality
36. Built-in Types: Patch
entity PageDiff {
page -> Page
next -> PageDiff
title :: String
patch :: Patch
created :: Date extend entity Page {
previous -> PageDiff function makeChange(.., newText : WikiText,...)
date :: Date : Page {
author -> User PageDiff {
version :: Int ...
} patch := newText.makePatch(this.content)
...
}
}
}
extend entity PageDiff {
function computeContent() : WikiText {
if (next = null) {
return patch.applyPatch(page.content);
} else {
return patch.applyPatch(next.content);
}
}
37. Foreign Function Interface
def f f
def prim(f)
prim(f)
call f f
call
declare functions/types available in 'native' libraries
40. Multiple Models / Multiple DSLs
split model into several models
combine DSLs to increase coverage
41. Multiple Models / Multiple DSLs
LEX
LEX YACC
YACC
CC CC
LEX: lexical analysis with regular grammars
YACC: context-free analysis with context-free grammars
42. Multiple Models / Multiple DSLs
DM
DM UI
UI AC
AC
JPA
JPA Servlets
Servlets Checks
Checks
DM: data model
UI: user interface
AC: access control
43. Model/Model Interaction
consider models as components / modules
what is interface of a model? what is the scope of model elements
model encapsulation; separate compilation
44. LEX & YACC
"PRINT" {{ return PRINT; }}
"PRINT" return PRINT;
[0-9]+
[0-9]+ {{ yylval == atoi(yytext); return NUMBER; }}
yylval atoi(yytext); return NUMBER;
[a-z]
[a-z] {{ yylval == yytext[0] -- 'a'; return NAME; }}
yylval yytext[0] 'a'; return NAME;
{{ ;; }}
n
n {{ nextline(); }}
nextline();
t
t {{ ;; }}
"//".*n {{ nextline(); }}
"//".*n nextline();
.. {{ yyerror("illegal token"); }}
yyerror("illegal token");
statement:
statement:
designator ASSIGN expression
designator ASSIGN expression
|| PRINT expression
PRINT expression
|| IF expression THEN stmtseq ELSE stmtseq FI
IF expression THEN stmtseq ELSE stmtseq FI
|| IF expression THEN stmtseq FI
IF expression THEN stmtseq FI
|| WHILE expression DO stmtseq OD
WHILE expression DO stmtseq OD
;;
47. Embedded Domain-Specific Languages
DSL assimilate GPL
GPL compile 'machine'
'machine'
assimilate compile
prog program
program code
code
MetaBorg (OOPSLA'04)
DSLs for abstraction over libraries/frameworks
fine-grained interaction with 'host' code
language conglomerates mix DSL and GPL code
48. Swing Userinterface Language
import javax.swing.*;
import java.awt.*;
public class Test3 {
public static void main(String[] ps) {
JFrame frame = frame {
title = "Welcome!"
content = panel of border layout {
center = label { text = "Hello World" }
south = panel of grid layout {
row = {
button { text = "cancel" }
button { text = "ok"}
}
}
}
};
frame.pack();
frame.setVisible(true);
}
}
49. DSL with embedded GPL Code
assimilate compile 'machine'
'machine'
assimilate compile
code
code
provide GPL expressivity/coverage to complement DSL
51. Mixing DSLs: HQL in WebDSL
function sortedBlogEntries(b : Blog) : List<BlogEntry> {
var entries : List<BlogEntry> :=
select distinct e from BlogEntry as e, Blog as b
where (b = ~b) and (e member of b._entries)
order by e._created descending;
return entries;
}
54. regular evolution
DSL
DSL DSL
DSL
DSL DSL
program
program modify program
program
prog modify prog
(model)
(model) (model)
(model)
regular evolution: adapt software to new requirements
implementation simply regenerated after modification of models
55. language evolution
DSL
DSL
DSL
program
program
prog
(model)
(model)
evolve
evolve
language (syntax and/or transformations) evolve
56. model migration
DSL
DSL DSL
DSL
DSL DSL
program
program migrate program
program
prog migrate prog
(model)
(model) (model)
(model)
evolve
evolve
language evolution requires migration of models
57. platform evolution
DSL
DSL DSL
DSL
DSL DSL
program
program program
program
prog prog
(model)
(model) (model)
(model)
evolve
evolve
evolve
evolve
changes in the platform requires evolution of transformations
58. model extraction
DSL
DSL DSL
DSL
DSL DSL
program
program abstract program
program
prog abstract prog
(model)
(model) (model)
(model)
derive DSL programs from (legacy) GPL programs
59. abstraction evolution
DSL
DSL
DSL
program
program
prog
(model)
(model)
abstract
DSL
DSL
DSL
program
program
prog
(model)
(model)
develop higher-level abstractions
60. Coupled Evolution
Data
Data Data
Data
evolve
evolve
model
model Model'
Model'
Data migrate Data'
Data'
Data migrate
61. Schedule
● Lab: implement your DSL
● Design 1: demonstrations Thursday and Friday
● Cases: grades coming up
● Lecture 13: Betsy Pepels from CapGemini
● Lecture 14: Johan den Haan & Michel Westrate from Mendix