Programming in UML: Why and How

6,756 views

Published on

Presentation given at the Symposium on Eclipse Open Source Software & OMG Open Specifications

Published in: Technology, Education
1 Comment
2 Likes
Statistics
Notes
No Downloads
Views
Total views
6,756
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
160
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

Programming in UML: Why and How

  1. 1. Programming in UML: Why and How Ed Seidewitz
  2. 2. Modeling for Software Development <ul><li>But… </li></ul><ul><li>It is hard to validate the correctness of the models before development. </li></ul><ul><li>The developers may not follow the models, without providing feedback. </li></ul><ul><li>It is hard to keep the models and development artifacts in sync during development (and maintenance). </li></ul>How it usually works Developers provide feedback to the architects (maybe) Architects give models to developers Developers create artifacts based on the models (maybe) Architects create the models
  3. 3. Modeling for Software Development <ul><li>Code-based development </li></ul><ul><ul><li>Use models for initial design, but then focus on code </li></ul></ul><ul><ul><li>Pro: Code is single source of &quot;truth&quot; </li></ul></ul><ul><ul><li>Con: Code is not as good for expressing design as models </li></ul></ul><ul><li>Model-driven development </li></ul><ul><ul><li>Use models as the source artifacts for development </li></ul></ul><ul><ul><li>Pro: Models can be more easily understood and evolved by human developers and maintainers. </li></ul></ul><ul><ul><li>Con: Model must be detailed enough to be executable in its own right. </li></ul></ul>Two responses But is this really a “con”??
  4. 4. Executable UML: Perceived Issues <ul><li>Making models detailed enough for machine execution defeats the purpose of models for human communication. </li></ul><ul><li>UML is not specified precisely enough to be executed (at least not in a standard way). </li></ul><ul><li>Graphical modeling notations are not good for detailed programming. </li></ul>
  5. 5. Executable UML: Issue Resolutions <ul><li>Making models detailed enough for machine execution defeats the purpose of models for human communication. </li></ul><ul><ul><li>Executable models can still be more understandable than executable code. </li></ul></ul><ul><ul><li>Non-executable models are still useful, too. </li></ul></ul><ul><li>UML is not specified precisely enough to be executed (at least not in a standard way). </li></ul><ul><ul><li>The Foundational UML (fUML) standard specifies precise semantics for an executable subset of UML. </li></ul></ul><ul><ul><li>Final adoption of fUML Version 1.0 by OMG Board of Directors is expected soon. </li></ul></ul><ul><li>Graphical modeling notations are not good for detailed programming. </li></ul><ul><ul><li>Concrete Syntax for a UML Action Language RFP requests a standard textual action language with fUML semantics. </li></ul></ul><ul><ul><li>Action Language for fUML (Alf) submission in progress. </li></ul></ul>
  6. 6. Architecture for Executable UML Tooling A virtual machine based on concurrent UML activity flow semantics. The target for “compiled” models. Providing all the capabilities expected in a code-based IDE. In memory or via XMI transfer. Simulation, analysis, optimization, etc. fUML Execution Engine Model Development Environment Other Tools Target Platform
  7. 7. Modeling for Software Development The models are the source code. Using a standard-conforming UML modeling tool Using a standard-conforming UML execution tool How it works with executable models Architects validate the models by executing them in a simulated test environment Technologists specify the implementation platform The models are provisioned as executing artifacts on the target platform Architects create the models
  8. 8. Programming in UML … is just programming, only better! The models are validated in a development/test environment The models are deployed in a production environment Developers create fully executable models Developers iteratively execute, test and update the models
  9. 9. Example: Property Management SOA <ul><li>Graphical UML notation for </li></ul><ul><ul><li>Data model </li></ul></ul><ul><ul><li>Message model </li></ul></ul><ul><ul><li>Interface and class models </li></ul></ul><ul><ul><li>Component models </li></ul></ul><ul><li>Textual Alf notation for </li></ul><ul><ul><li>Operation methods </li></ul></ul>
  10. 10. Property Data Model
  11. 11. Service Request Message Model
  12. 12. Service Reply Message Model
  13. 13. Service Interface and Implementation
  14. 14. Service Provider Component Composite structure and ports are not in fUML, but they can be interpreted per SoaML.
  15. 15. Operation method: establish <ul><li>/** Establish a new property record. */ </li></ul><ul><li>activity establish ( </li></ul><ul><li>in request: 'Property Record Establishment', </li></ul><ul><li>out reply: 'Property Management Success Reply' [0..1], </li></ul><ul><li>out error: 'Error Reply' [0..1] ) { </li></ul><ul><li>identifier = this.'property identifier factory'.'get next identifier'(); </li></ul><ul><li>if (request.'property type' == 'Property Type'::personal) { </li></ul><ul><li>property = new 'Personal Property'::'create property'(identifier,request.name); </li></ul><ul><li>} else { </li></ul><ul><li>property = new 'Real Property'::'create property'(identifier,request.name); </li></ul><ul><li>} </li></ul><ul><li>reply = this.'create reply'(request.identifier, property); </li></ul><ul><li>} </li></ul>Operation methods are specified as UML activities. Newly created objects persist at the current execution locus. Names can have spaces or other special characters.
  16. 16. Operation method: update <ul><li>/** Update the data of a property other than acquisition or disposition. */ </li></ul><ul><li>activity update ( </li></ul><ul><li>in request: 'Property Record Update', </li></ul><ul><li>out reply: 'Property Management Success Reply' [0..1], </li></ul><ul><li>out error: 'Error Reply' [0..1] ) { </li></ul><ul><li>property = Property -> select p (p.identifier == request.'property identifier'); </li></ul><ul><li>if (property -> isEmpty()) { </li></ul><ul><li>error = new 'Error Reply' ( </li></ul><ul><li>identifier => request.identifier + &quot;/error&quot;, </li></ul><ul><li>'request identifier' => request.identifier, </li></ul><ul><li>'error code' => &quot;PRU-001&quot;, </li></ul><ul><li>'error message' => &quot;Property not found.&quot; ); </li></ul><ul><li>} else if (property.status == 'Property Type'::disposed) { </li></ul><ul><li>… </li></ul><ul><li>} else { </li></ul><ul><li>if (request.'property location' -> notEmpty()) { </li></ul><ul><li>location = Location -> select loc </li></ul><ul><li>(loc.identifier == request.'property location'); </li></ul><ul><li>'Property Location'.createLink(property, location); </li></ul><ul><li>} </li></ul><ul><li>… </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>A “select” maps to a concurrent expansion region over a class extent. Creating a link automatically establishes a bidirectional relationship.
  17. 17. References <ul><li>Foundational UML (fUML) </li></ul><ul><ul><li>Semantics of a Foundational Subset for Executable UML Models standard, http://www.omg.org/spec/fuml </li></ul></ul><ul><ul><li>fUML Reference Implementation Project, http://www.modeldriven.org/fuml </li></ul></ul><ul><li>Action Language for fUML (Alf) </li></ul><ul><ul><li>Concrete Syntax for a UML Action Language RFP, http://www.omg.org/cgi-bin/doc?ad/2008-09-09 </li></ul></ul><ul><ul><li>Submission repository, http://lib.modeldriven.org/MDLibrary/trunk/Applications/Alf-Reference-Implementation </li></ul></ul><ul><ul><ul><li>/doc – Latest submission document and current working draft </li></ul></ul></ul><ul><ul><ul><li>/dist – Parser for latest working version (currently v0.08) </li></ul></ul></ul><ul><li>Contact </li></ul><ul><ul><li>[email_address] </li></ul></ul><ul><ul><li>http://twitter.com/seidewitz </li></ul></ul>

×