Presentation is loading. Please wait.

Presentation is loading. Please wait.

Model Driven Engineering

Similar presentations


Presentation on theme: "Model Driven Engineering"— Presentation transcript:

1 Model Driven Engineering
UML class diagrams object diagrams and constraints metamodeling examples MDE finally! basics of Model Driven Engineering

2 MDE Is about automating the development of rote well-understood software everything that I talk about you have done or will do manually Generalizes standard Engineering practices engineering with a capital “E” where one creates a model or models of what needs to be built, and tools transform this model or models into an engineering artifact. Ex: Next generation space shuttle Software development becomes creating models and applying M2M and M2T transformations to generate source code. Instead you write models of programs, or if you are advanced you write model-to-model (M2M) or model-to-tool (M2T) or tool-to-model (T2M) transformations

3 Quick Sketch of MDE General idea is to have domain experts draw a diagram model of what they want Press a button and the model translated to a database Database is checked for constraint violations If no violations, transform to code or code shell that has to be filled in T2M M2T Violet or UML Drawing Tool Constraint Verification Let’s look at an example to make this concrete

4 An MDE Model Here is a finite state machine (FSM) model of my eating habits: In general, a model is a graph different nodes have different icons to represent different semantics edges possibly directed represent relationships different edges have different icons to represent different semantics

5 Everything is a Graph to MDE nothing special about FSMs
Everything is a Graph to MDE nothing special about FSMs. hence the generality of MDE Message Sequence Charts Logic Circuit Diagram Data Flow Model Petri Net Network Architecture Flow Chart

6 All are Object Diagrams
Everything is a Graph to MDE nothing special about FSMs. hence the generality of MDE Message Sequence Charts Logic Circuit Diagram Data Flow Model All are Object Diagrams Petri Net Network Architecture Flow Chart

7 MDE FSM Engineer has 2 Tasks
To use a special tool to draw the desired FSM graph

8 MDE FSM Engineer has 2 Tasks
To press a button not shown to generate code that implements the drawn graph Basic questions to ask: how does the FSM tool work internally? how is application source generated? FSM Application Engineer FSM tool FSM source code draws FSM presses button to generate

9 to answer these questions, we need to look a bit deeper
Metamodels

10 Draw its UML Class Metamodel
MDE Metamodel It is a specification of all legal graphs of a kind Show simplest UML class diag. that represents all FSM graphs as below? node = class edge = association or inheritance relationship Answer on next slide Draw its UML Class Metamodel

11 MDE Metamodel A schema for this diagram is: do Node schema first node#
name type trans# startsAt endsAt of type Node# note: things like “1” and “*” are expressed by constraints. In this case, every transition MUST have non-empty StartsAt and EndsAt fields.

12 Populating Tables with Tuples
Given the following FSM instance: Its tabular representation is: trans# startsat endsat t1 nstart nReady t2 nDrink t3 nEat t4 t5 t6 t7 t8 nFam t9 t10 nstop node# name type nstart start nReady Ready state nDrink Drink nEat Eat nFam Family… nstop stop

13 Recall Actions of Engineer
Draw FSM and push button Press button arrow is a composition of 3 more primitive arrows a.k.a. steps presses button to generate FSM source code FSM tool draws FSM using Application Engineer parse graph into tables FSM model xform tables to code FSM source code validate constraints

14 From Relational Tables…
Can generate code because FSM application domain is well-understood The essence of MDE! rote mapping Called a Model to Text (M2T) transformation

15 I previously used Velocity, which sucked, and now I’m using Running Bear
a Model to Text tool

16 Model to Text Mapping Running Bear (RB) is a teeny-weeny Java package
There are lots of “off-the-shelf” tools; I previously used Apache Velocity but RB is much better. Database tables in RB are database tuples or prolog facts Example: class diagrams with no methods or associations – translate them to Java code. What is the simplest metamodel of these instances? Answer on next slide

17 Example Metamodel and Instances
What is the schema of this metamodel? do class schema first What are the tuples? do class table first class# name attribute# name type ofclass class# name c1 City c2 Account attribute# name type ofclass a1 String c1 a2 state a3 number Integer c2 a4 balance Double

18 Translation to Databases
Relational tables: Relational database ≈ prolog fact file data.pl dbase(data,[class,attribute]). table(class,[cid,name]). class(c1,city). class(c2,account). table(attribute,[aid,name,type,ofclass]). attribute(a1,name,string,c1). attribute(a2,state,string,c1). attribute(a3,number,integer,c2). attribute(a4,balance,double,c2). class# name c1 City c2 Account green is schema black is data attribute# name type ofclass a1 String c1 a2 state a3 number Integer c2 a4 balance Double

19 All 6 RB Methods static void setOut(PrintStream out) // set file output, stdout is default static void l(String fmt, Object... args) { out.format(fmt + "\n", args); } static void l() { out.println(); } // print new blank line static void p(String fmt, Object... args) { out.format(fmt, args); } static void close() // close file output, reset to stdout marquee(String… args) // main processing

20 > java RBProgram <database> [output-file]
Hello World! General calling sequence of an RB program: > java RBProgram <database> [output-file] > java helloworld ignore.db.pl supply dummy argument produces:

21 Example RB Program data.pl > java gen data.pl gen.java class city {
string name; string state; } class account { integer number; double balance; data.java > java gen data.pl dbase(data,[class,attribute]). table(class,[cid,name]). class(c1,city). class(c2,account). table(attribute,[aid,name,type,cid]). attribute(a1,name,string,c1). attribute(a2,state,string,c1). attribute(a3,number,integer,c2). attribute(a4,balance,double,c2). data.pl gen.java gen.java

22 Example RB Program data.pl > java gen data.pl gen.java
class city { string name; string state; } src/city.java class account { integer number; double balance; src/account.java > java gen data.pl dbase(data,[class,attribute]). table(class,[cid,name]). class(c1,city). class(c2,account). table(attribute,[aid,name,type,cid]). attribute(a1,name,string,c1). attribute(a2,state,string,c1). attribute(a3,number,integer,c2). attribute(a4,balance,double,c2). data.pl gen.java

23 Time for Perspective

24 In Programming Assignment P1
You translated Java bytecode files into an MDELite database Called a Tool-to-Model transformation – generally it is a Java program RB is a tool that translates a MDELite database into a text file; called a Model-to-Text (or Model-to-Tool) transformation T2M M2T

25 A Possible Programming Assignment
Write the M2T transformation using the RB tool and Apache Velocity for comparison -- I’ll give you the FSM database to translate M2T mapping

26 Programming assignments P2 and P3
big picture for P2 and P3 Programming assignments P2 and P3

27 Your 2nd Programming Assignment
Verify that a Violet UML class diagram is “correct”, meaning that it conforms to sensible constraints Violet was given to you Violett.ClassParser was given to you You wrote VPL.Conform Violett.ClassParser VPL.Conform Violet to draw a class diagram

28 Your 3RD Programming Assignment
vpl2ypl ClassUnparser P3 ClassParser P2 .Conform P3 is next step in this chain – You translated a VPL database into a YPL database, and used an existing tool that converted a YPL database into a Yuml spec. This is a M2M (model-2-model) transformation Doing so, you wrote your first simple (MDE) application! public static void main(String… args) { MDL.VioletClassParser.main(args[0],args[1]); // produces new.vpl.pl VPL.Conform(args[1]); M2M.vpl2vpl(args[1], “new.ypl.pl”); Yuml.ClassUnParser(“new.ypl.pl”,”new.yuml.yuml”); } Approximate

29 Oops ! Not quite right What is missing?
ClassParser vpl2ypl ClassUnparser P3 P2 Conform Conform What is missing? Ans: YPL.Conform ! Just as VPL databases have conformance rules, so too do YPL databases. These rules are very similar to that of VPL. Yuml.Conform already exists, so you could call it immediately after your vpl2ypl program finishes execution.

30 Big Picture of MDE All categories: domains of design artifacts and arrows are programs Conform ToYumlSpec ClassParser

31 Big Picture of MDE All categories: domains of design artifacts and arrows are programs MDE programs are traversals of arrows of a category Violet MM VPL Boolean yUML Specs Conform ClassParser ToYumlSpec Conform ClassParser ToYumlSpec

32 If I were to Give Another MDE Programming Assignment
I’d have you integrate P1, P2, P3 or use RB to generate Java stubs genStub MDE is linking these domains together into an interoperable ecosystem introspect P4 prog1toVPL ClassParser vpl2ypl yumlspec Conform Conform

33 Recap FSM Application Engineer uses an FSM tool to draw a desired FSM The tool internally stores a model as a set of relational tables Database is validated Tool translates these tables into source code using RB Conform Application Engineer FSM tool relational tables draws FSM using stores FSM graph in RB script translates to code application source code Questions?

34 Refactorings Next Lecture
Other transformations are used to build models and meta-models called: They are also a centerpiece for Java and OO program development Refactorings


Download ppt "Model Driven Engineering"

Similar presentations


Ads by Google