uml based automated code generation uml based automated code generation ieee computer society...
TRANSCRIPT
UML Based Automated Code UML Based Automated Code GenerationGeneration
IEEE Computer Society PhoenixHaseeb AhmedMotorola Inc.
November 7, 2007
November 7, 2007November 7, 2007
AgendaAgenda
UML and ModelingUML and Modeling
Auto-CodingAuto-Coding
Unifying Modeling & Auto-Code Unifying Modeling & Auto-Code GenerationGeneration
Applicability.Applicability.
Demonstration with Telelogic’s Tau G2.Demonstration with Telelogic’s Tau G2.
Open ForumOpen Forum
November 7, 2007November 7, 2007
UML and ModelingUML and Modeling
Why UML?Why UML?– Late 80s and early 90s saw a quantum leap in Late 80s and early 90s saw a quantum leap in
software development (and revenues).software development (and revenues).– Industry needed a Standardized view of Industry needed a Standardized view of
representation.representation.– Answer: The Unified Modeling LanguageAnswer: The Unified Modeling Language
November 7, 2007November 7, 2007
UML – Simply put…UML – Simply put…
Served as a unifying ‘language’ for software.Served as a unifying ‘language’ for software.– StandardizedStandardized– Agnostic to platform, OS and programming languageAgnostic to platform, OS and programming language
The ‘Language’ consisted of pictorial The ‘Language’ consisted of pictorial representations for various software artifacts:representations for various software artifacts:
– ClassesClasses– State MachinesState Machines– Sequence DiagramsSequence Diagrams– An excellent reference:An excellent reference:
The Unified Modeling Language - The Unified Modeling Language - http://www-306.ibm.com/software/rational/uml/http://www-306.ibm.com/software/rational/uml/
November 7, 2007November 7, 2007
UML in Pictures: Use CasesUML in Pictures: Use Cases
Source: http://www.telelogic.com/campaigns/2003/global/taug22_launch/iuseuml1x.cfm
November 7, 2007November 7, 2007
UML in Pictures: Class DiagramsUML in Pictures: Class Diagrams
Source: http://www.telelogic.com/campaigns/2003/global/taug22_launch/iuseuml1x.cfm
November 7, 2007November 7, 2007
UML in Pictures: State Chart DiagramUML in Pictures: State Chart Diagram
Source: http://www.telelogic.com/campaigns/2003/global/taug22_launch/iuseuml1x.cfm
November 7, 2007November 7, 2007
UML in Pictures: Architecture DiagramUML in Pictures: Architecture Diagram
Source: http://www.telelogic.com/campaigns/2003/global/taug22_launch/iuseuml1x.cfm
November 7, 2007November 7, 2007
UML in Pictures: Sequence DiagramsUML in Pictures: Sequence Diagrams
Source: http://www.telelogic.com/campaigns/2003/global/taug22_launch/iuseuml1x.cfm
November 7, 2007November 7, 2007
ModelingModeling
More precisely: ‘Model Driven Architecture’.More precisely: ‘Model Driven Architecture’.Definition: A representation that focuses on the Definition: A representation that focuses on the functionality and behavior of an application (or functionality and behavior of an application (or system) and is agnostic to the underlying system) and is agnostic to the underlying platform, OS or programming language used.platform, OS or programming language used.
This is really a tall order given the spectrum of This is really a tall order given the spectrum of choices for platforms, OSs and languages today!choices for platforms, OSs and languages today!For this presentation, I’ll limit myself to Modeling For this presentation, I’ll limit myself to Modeling with UML.with UML.
November 7, 2007November 7, 2007
ModelingModeling
In practice, modeling relies on UML for In practice, modeling relies on UML for abstracting everything from a small abstracting everything from a small application to a complex system.application to a complex system.– A typical Model may consists of:A typical Model may consists of:
Classes, Objects DiagramsClasses, Objects DiagramsState Machine DiagramsState Machine DiagramsSequence/Activity DiagramsSequence/Activity DiagramsArchitecture DiagramsArchitecture DiagramsDeployment DiagramsDeployment Diagrams… … even Use Caseseven Use Cases
November 7, 2007November 7, 2007
ModelingModeling
Typically, a software engineer will use a Typically, a software engineer will use a GUI or CASE tool to represent the GUI or CASE tool to represent the application or system.application or system.The tool largely facilitates this by enforcing The tool largely facilitates this by enforcing sanity of the application or system design.sanity of the application or system design.– For example:For example:
Verifying valid state transitionsVerifying valid state transitions Automating message transmission and receptionAutomating message transmission and reception
UML is a natural fit.UML is a natural fit.
November 7, 2007November 7, 2007
UML+Modeling = ?UML+Modeling = ?
Once an application or system is fully Once an application or system is fully modeled in UML, the next self-evident step modeled in UML, the next self-evident step is to generate the source code.is to generate the source code.
Also known as…Also known as…
Most modern modeling tools provide this Most modern modeling tools provide this capability ‘built-in’.capability ‘built-in’.
November 7, 2007November 7, 2007
Auto-CodingAuto-Coding
Strictly speaking: ‘Automated Code Strictly speaking: ‘Automated Code Generation’Generation’
Definition: A way to automagically Definition: A way to automagically synthesize code for an application or synthesize code for an application or system from a model, following UML and system from a model, following UML and Modeling constructs.Modeling constructs.
November 7, 2007November 7, 2007
Modeling & Auto-Code Generation: Modeling & Auto-Code Generation: A High Level ViewA High Level View
AutoCode
Generator
OS Platform
UMLModels
6. Application Binary executing on Target OS/Platform
1. Create UML Model
2. Model Sanity Checked
3. Auto-Code Generation
4. Source Code ‘Ready to Build’
5. Compile & Build into Application Binary
UM
L M
odel
ing
Too
l
November 7, 2007November 7, 2007
Auto-Coding: The Silent SidekickAuto-Coding: The Silent Sidekick
Auto-coding not so new in software Auto-coding not so new in software development.development.
Often used for things which are tedious and Often used for things which are tedious and repetitive, e.g.;repetitive, e.g.;– Generating ASN.1 code.Generating ASN.1 code.– Lex/YACC/Bison suite of tools for generating Lex/YACC/Bison suite of tools for generating
customized code for Unix based platforms.customized code for Unix based platforms.
Usage generally ‘invisible’ because the auto-Usage generally ‘invisible’ because the auto-coding syntax used is quite cryptic and not very coding syntax used is quite cryptic and not very exciting to the broader engineering community.exciting to the broader engineering community.
November 7, 2007November 7, 2007
With higher level abstractions (UML, With higher level abstractions (UML, Modeling etc.) available, auto-coding can Modeling etc.) available, auto-coding can now generate full applications.now generate full applications.From the 50,000 ft Level:From the 50,000 ft Level:
However, tool offerings may be more or However, tool offerings may be more or less compliant than what you would less compliant than what you would expect.expect.
C/C++ : Assembly Code :: Modeling : Handwritten Code
Auto-Coding: UnleashedAuto-Coding: Unleashed
November 7, 2007November 7, 2007
Auto-Coding: UnleashedAuto-Coding: Unleashed
Many UML Model artifacts are just what Many UML Model artifacts are just what we expect:we expect:– UML Class UML Class C++ Class/C Structure C++ Class/C Structure– UML Operation UML Operation C/C++ Function C/C++ Function
Some are a bit more abstract:Some are a bit more abstract:– UML Signals UML Signals C/C++ Function calls. C/C++ Function calls.
Think Callbacks for Input Signals and Function Think Callbacks for Input Signals and Function calls for Outbound signals.calls for Outbound signals.
November 7, 2007November 7, 2007
Auto-Coding: UnleashedAuto-Coding: Unleashed
And some may be surprising:And some may be surprising:– Item widget[45]Item widget[45]
May Generate a simple Array of 45 elements.May Generate a simple Array of 45 elements.
May Generate a Linked List of 45 ‘Item’ nodes May Generate a Linked List of 45 ‘Item’ nodes each with 1 widget.each with 1 widget.
– TimersTimers Set/Expire implementation based on tool and Set/Expire implementation based on tool and
code generator.code generator.
Timer ticks or TimeOfDay()Timer ticks or TimeOfDay()
November 7, 2007November 7, 2007
Auto-Coding: ChallengesAuto-Coding: Challenges
This brings new challenges and concerns:This brings new challenges and concerns:– Performance of the generated code.Performance of the generated code.– Perfection of generated code to model.Perfection of generated code to model.
Accurate conversion of model to code?Accurate conversion of model to code?
– Implementation quirks:Implementation quirks:Auto-code generation is not standardized.Auto-code generation is not standardized.
Remember the ‘Agnostic to the platform, OS and language’ Remember the ‘Agnostic to the platform, OS and language’ requirement – what is the cost of portability?requirement – what is the cost of portability?
– Hard to compete (read: beat) hand written code in the Hard to compete (read: beat) hand written code in the short term.short term.
November 7, 2007November 7, 2007
Modeling & Auto-Code Key BenefitsModeling & Auto-Code Key Benefits
Higher Level Modeling emphasizes Design & Architectural Discipline.Higher Level Modeling emphasizes Design & Architectural Discipline.
Des
ign
Many Tools provide built-in simulators.Many Tools provide built-in simulators.Execute the Model to see how it flows right from your Desktop.Execute the Model to see how it flows right from your Desktop.
Rapid Prototyping possible for feature rich models.Rapid Prototyping possible for feature rich models.Tes
t
Auto-coding follows a set of rules for generating code.Auto-coding follows a set of rules for generating code.Quality is consistent.Quality is consistent.
Avoids some egregious human errors (e.g., null pointers).Avoids some egregious human errors (e.g., null pointers).Qua
lity
Cycle Time ReductionCycle Time ReductionCost of Poor Quality ContainmentCost of Poor Quality Containment
(Hopefully) Better Software Design & Architecture.(Hopefully) Better Software Design & Architecture.Ove
rall
November 7, 2007November 7, 2007
ApplicabilityApplicability
Well suited for Well suited for Applications which Applications which lend nicely to State lend nicely to State Machine Machine Architectures.Architectures.
Protocols – Network, Protocols – Network, Telephony… Telephony… Request/Reply, Request/Reply, Transactional.Transactional.
SimulationSimulation
Rapid PrototypingRapid PrototypingPicture Source: http://www.omg.org/mda
November 7, 2007November 7, 2007
CaveatsCaveats
UML and Object Oriented Design: They UML and Object Oriented Design: They are not the same.are not the same.In Modeling, easy to make big mistakes. In Modeling, easy to make big mistakes. (mostly easy to correct too, but not (mostly easy to correct too, but not always!)always!)Auto-coding best when it’s impacts are Auto-coding best when it’s impacts are invisible.invisible.Performance and Portability must be Performance and Portability must be carefully weighed.carefully weighed.
November 7, 2007November 7, 2007
DemoDemo
Tool: Telelogic’s Tau G2.Tool: Telelogic’s Tau G2.
Example:Example: Construction of a request/response system within Construction of a request/response system within a non-trivial model.a non-trivial model.
Miscellaneous:Miscellaneous: Highlight the simulation capabilities.Highlight the simulation capabilities.
Injection of messages, auto generation of Injection of messages, auto generation of sequence diagrams.sequence diagrams.
November 7, 2007November 7, 2007
Operating System
Tau G2 App. ArchitectureTau G2 App. Architecture
‘Glue’MWAPI
Middleware Services
Middleware to Interface generated code with custom libraries.
Middleware ‘glue’ for specialized services.
Auto Generated Code
UML Model
Application plus Tau G2 ‘kernel’
The Application/System
The ‘environment’
November 7, 2007November 7, 2007
Open ForumOpen Forum
Q & AQ & A
November 7, 2007November 7, 2007
ReferencesReferences
1.1. The Unified Modeling Language - The Unified Modeling Language - http://www-306.ibm.com/software/rational/uml/http://www-306.ibm.com/software/rational/uml/ 2.2. Tau G2 – Telelogic – Tau G2 – Telelogic – http://www.telelogic.comhttp://www.telelogic.com3.3. The Object Management Group - The Object Management Group - http://www.omg.org/mdahttp://www.omg.org/mda4.4. Automatic Code Generation from Design Patterns - Automatic Code Generation from Design Patterns -
http://www.research.ibm.com/designpatterns/pubs/codegen.pdfhttp://www.research.ibm.com/designpatterns/pubs/codegen.pdf5.5. UML Forum (Modeling Tool Comparisons) - UML Forum (Modeling Tool Comparisons) - http://www.uml-forum.com/tools.htmhttp://www.uml-forum.com/tools.htm