model driven development and code generation

30
Model Driven Development and Code Generation Make the Model Do the Work Chip Temm

Upload: arnaldo-cruz

Post on 31-Dec-2015

32 views

Category:

Documents


0 download

DESCRIPTION

Model Driven Development and Code Generation. Make the Model Do the Work Chip Temm. Target Audience. Small Teams in Medium-sized Workgroups Established processes Discussion Light process and tooling to produce rapid results and reduce overhead of new projects & system maintenance. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Model Driven Development and  Code Generation

Model Driven Development and

Code Generation

Make the Model Do the WorkChip Temm

Page 2: Model Driven Development and  Code Generation

Target Audience

Small Teams in Medium-sized Workgroups• Established processes

Discussion• Light process and tooling to produce rapid results and

reduce overhead of new projects & system maintenance. • Model driven as differentiated from database-driven.• Linking modeling to code generation.• Not describing MDA.• Forward looking – not all of what is discussed exists

Page 3: Model Driven Development and  Code Generation

Where I’m Coming From

Managing matrixed development teams Quality is key Process matters Trying to find balance between quality

and accuracy Understanding team drivers

Page 4: Model Driven Development and  Code Generation

MDD can help teams improveD

ocu

menta

tion

Development

Design

Maintenance

Page 5: Model Driven Development and  Code Generation

Documentation

Challenge: Getting code documented Challenge: Keeping docs in sync “Painful, boring, tedious” Who is it for? De-prioritized Important

• Memory Reallocation• Staff Turnover• HBAB

Page 6: Model Driven Development and  Code Generation

Document the Design

Makes less sense to document after the code is done

Model Metadata:• Communicates the original intention of the

concepts modeled• Drives / can be derived from component

metadata

Page 7: Model Driven Development and  Code Generation

Design

Design docs as communication Reduce code-as-you-go Enable better re-use

Page 8: Model Driven Development and  Code Generation

Development

Forward generate the repetitive Enable easier distribution of work Outlined development

Page 9: Model Driven Development and  Code Generation

Maintenance

Forward-generating new components is easier when you can see the rest of the model.

Know the ramifications of what you change Refactoring can be easier: metaprogramming … or at least no harder: round-tripping is a

challenge. Help get unit tests framed up

Page 10: Model Driven Development and  Code Generation

Using modelling tools.

Tools overview Approaches to generation

• Exporting to XMI• Tool-based generation

Page 11: Model Driven Development and  Code Generation

Tools Overview

Most UML modeling tools now support code generation• Java is a key target• ColdFusion not supported out of the box

Most tools export to XMI• Some have extended XMI• Different flavors

Page 12: Model Driven Development and  Code Generation

Sampling of tools

Tigris.org• ArgoUML -opensource

SparxSystems • Enterprise Architect- $200

Gentlesoft• Poseidon- $900 (cfcxmi plugin)

Page 13: Model Driven Development and  Code Generation

Approaches to generation

Write your own generator Modify a tool’s generation

templates

Page 14: Model Driven Development and  Code Generation

Exporting to XMI

Pros: If you want to • write your own generators• pick your language• Modeling independence (ish)

Cons: • XMI is not the most readable• You do the heavy lifting

Page 15: Model Driven Development and  Code Generation

XML Transformation

Page 16: Model Driven Development and  Code Generation

ModelGlue Transformation

<?xml version="1.0" encoding="UTF-8" ?> - <xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  <xsl:output method="text" indent="no" /> - <xsl:template match="/">  <cfset listEvent = viewstate.getValue("myself") &

viewstate.getValue("xe.list") /> <cfset commitEvent = viewstate.getValue("myself") & viewstate.getValue("xe.commit") & "&

  <xsl:value-of select="object/name" />   Id=" & urlEncodedFormat(viewstate.getValue("   <xsl:value-of select="object/name" />   Id")) /> <cfset   <xsl:value-of select="object/name" />   = viewstate.getValue("

Page 17: Model Driven Development and  Code Generation

Example CF Char Sub Transform

…«cfstoredproc procedure=“#currentTable#_Insert"

datasource="$application.datasource$" »<cfloop collection="#currentcfc.properties#" item="thisProp" >«cfprocparam value="$variables.instance.#thisProp#$" type="In" /»</cfloop>«cfprocparam variable="objectID" type="Out" /»

«/cfstoredproc»

«cfset variables.instance.objectID = objectID /»«cfreturn variables.instance.objectID/»

Page 18: Model Driven Development and  Code Generation

CF Parsing of XMI

    <cfscript>      xmlDoc = xmlparse('OpenModel.xmi');      classes = xmlsearch(xmlDoc,"//UML:Class[@xmi.id]");      classesLen = arrayLen(classes);      for(i=1;i lte classesLen;i=i+1){        thisClass = classes[i];        //now loop down into properties, methods and arguments      }    </cfscript>

Page 19: Model Driven Development and  Code Generation

Using tool-based generation

Pros: • Tool does heavy lifting• Results are rapid• Toolset easily sharable

Cons• May have to learn a new language to write your

templating logic• Create your own datatypes…• Vendor lock-in

Page 20: Model Driven Development and  Code Generation

Poseidon template macro

See Eclipse…

Page 21: Model Driven Development and  Code Generation

Sparx Template Editor

Page 22: Model Driven Development and  Code Generation

Generating to frameworks

Frameworks are geared toward driving code into patterns

Repetition is a good target for automation Some existing frameworks have generation

capabilities but are not model-first Generate those ORM files from models

Page 23: Model Driven Development and  Code Generation

Converting Code to Models

Why? Code needs to have reliable metadata Reflection can be used to extract

information Layout of diagrams is no fun

Page 24: Model Driven Development and  Code Generation

Challenges to MDD

Technology Round-tripping Mindset Management

Page 25: Model Driven Development and  Code Generation

Challenge: Technology

Commercial pkgs geared toward• Larger shops• Mainstream languages

Can be expensive Learning curve Getting lost in the feature set

Page 26: Model Driven Development and  Code Generation

Challenge: Round-tripping

ColdFusion not XML compliant, hard to parse

Flex is probably a good target Version control

Page 27: Model Driven Development and  Code Generation

Challenge: Developer Mindset

Fear of ‘wizards’ Fear of change Fear of oppression

Page 28: Model Driven Development and  Code Generation

Challenge: Management

Requires investment• How many people do I have to train?• What processes do I have to change?• What will toolchain changes cost?

Where to allocate the risk of change?

Page 29: Model Driven Development and  Code Generation

Good Luck!

Presentation will be available later today at:

http://anthrologik.net/presentations/dc_frameworks_2007_02_01.ppt

Email: [email protected]://del.icio.us/chiptemm/http://cfdj.sys-con.com/author/temm.rss

Page 30: Model Driven Development and  Code Generation

Article

COMPONENTNAME e.g."XMI_Parser"[   name [string]   displayname [string]   hint [string]

    PROPERTIES[      PROPERTYNAME[        name [string]        type [string]        required [BOOLEAN]        displayname [string]        hint [string]        default [string]      ]    ]    FUNCTIONS[      FUNCTIONNAME[        string name [string]        access [string]        returntype [string]        roles [string]        hint [string]        output [BOOLEAN]        ARGUMENTS[          ARGUMENTNAME[            name [string]            type [string]            required [BOOLEAN            default [string]            hint [string]          ]        ]      ]    ]]