570 likes | 576 Views
Learn how to use Umple, an open source code generator for UML, that allows for textual modeling and seamless integration with other programming languages. Explore code generation, modeling tools, and the umplification process.
E N D
Textual Modeling and Model-Oriented Programming using Umple • Tutorial Slides • www.umple.org Models 2015 M. Garzón, A. Forward, and T. Lethbridge
Motivation • From our studies of practitioners • Code generation is weak in widely-deployed tools • Tools are awkward, do not interoperate • Modellers mostly • do it for documentation • make important errors • From our teaching of modeling • Students learned syntax, but failed to learn • Semantics • Pragmatics • To create implementable models due to lack of feedback Umple Tutorial
Umple: Simple, Ample,UML Programming Language • 1. Open source code generator for UML • The only one that has • Infinitely nested state machines, with concurrency • Proper referential integrity and multiplicity constraints on associations • 2. Textual modelling tool set • Command line compiler • Web-based tool (UmpleOnline) for demos and education • Eclipse plugin • 3. Pre-processor to add UML, patterns and other features on top of Java, PhPand other languages Umple Tutorial
Exercise: Compiling and Changing a Model • Go to http://helloworld.umple.org • Look at the example at the bottom • Observe: attribute, association, class hierarchy, mixin • Click on Load the above code into UmpleOnline • Observe and modify the diagram • Add an attribute • Make a multiplicity error, then undo • Generate code and take a look • Download, compile and run if you want Umple Tutorial
Hello World Example in the User Manual Umple Tutorial
Hello World Example in UmpleOnline Umple Tutorial
State machine example in UmpleOnline Umple Tutorial
State machine detail in the user manual • http://statemachines.umple.org Umple Tutorial
Demo of the command line Umple compiler • Follows conventions of gcc • Used by ant scripts for building Umple Tutorial
Umple Philosophy 1-4 • P1. Modeling is programming and vice versa • P2. An Umple programmer should never need to edit generated code to accomplish any task. • P3. The Umple compiler can accept and generate code that uses nothing but UML abstractions. • The above is the inverse of the following • P4. A program without Umple features can be compiled by an Umple compiler. • e.g. input Java results in the same as output Umple Tutorial
Umple Philosophy 5-8 • P5. A programmer can incrementally add Umple features to an existing program • Umplification • P6. Umple extends the base language in a minimally invasive and safe way. • P7. Umple features can be created and viewed diagrammatically or textually • P8. Umple goes beyond UML Umple Tutorial
Umplification • Umplification: ‘amplication’ + converting into Umple. • Produces a program with behavior identical to the original one, but written in Umple. • Eliminates the distinction between code and model. • Proceeds incrementally until the desired level of abstraction is achieved. Umple Tutorial
Umplification: The Transformation Steps • Transformation 0: Initial transformation • Transformation 1: Transformation of generalization, dependency, and namespace declarations. • Transformation 2: Analysis and conversion of many instance • variables, along with the methods that use the variables. • Transformation 2a: Transformation of variables to UML/Umple attributes. • Transformation 2b: Transformation of variables in one or more classes to UML/Umple associations. • Transformation 2c: Transformation of variables to UML/Umple state machines. Umple Tutorial
Umplification Process Umple Tutorial
Umplificator Architecture Umple Tutorial
Systems umplified • JhotDraw 7.5.1 Umple Tutorial
Systems umplified • JhotDraw 7.5.1 Umple Tutorial
Systems umplified • Weka – Associations umplified • Args4J- Modernization • OriginalArgs4j source code is composed of 61 classes and 2223 LOC. • Umplified Args4j source code is composed of 122 (2 per input class) umple files and 1980 LOC. • # LOC in files containing modeling constructs (X.ump) is 312. • # LOC in files with algorithmic/logic code (X code.ump) is 1668. • The developer must then translate 1518 lines of code rather than 2223 lines of code. Umple Tutorial
Attributes in Umple • More than just variables • http://attributes.umple.org Umple Tutorial
Attributes http://attributes.umple.org
Associations in Umple • Associations • http://associations.umple.org • Notice the inline and independent state machines Umple Tutorial
Associations http://associations.umple.org/
Association Relationships Directional Associations * -> 0..1, * -> 1, * -> *, * -> m..n, * - >n, *->m..* and*->0..n. Symmetric Reflexive 0..1, 0..n, *, 1, n, m..n,m..*
Code Generation Patterns Attributes Set/Get (UB = 1) Add/Remove/NumberOf/IndexOf/Get (UB > 1) Lazy immutability Default values Constants Before / After cod Associations Set/Get (UB = 1) Add/Remove/NumberOf/IndexOf/Get (UB > 1) Referential Integrity Multiplicity Constraints 42 different cases UB = upper bound
Code Generation (Sematics) http://api.umple.org
Umple Examples... http://try.umple.org https://github.com/umple/umple/wiki/examples
Umple Example Database http://try.umple.org http://umpr.a4word.com/
More example databases? Contact us through github.com/umple
Umple Plugin For Sublime 3 To Install cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/User git clone https://github.com/umple-ucsop/umple.sublime.git ./umple
Build Scripts Ant based scripts One master build.xml, with several project specific build.<proj>.xml Chains commands together instead of dependency heirarchies https://github.com/umple/Umple/wiki/CheatSheet
Docker Container (experimental) https://hub.docker.com/u/umple/dashboard/ mkdir ~/src && cd ~/src && git clone git@github.com:umple/umple.git docker run -i -t -v `pwd`:/src umple/umple:0.4.0 bash
Umple Architecture http://metamodel.umple.org http://grammar.umple.org/
Umple written in Umple http://code.umple.org http://metamodel.umple.org
Original (Pre-Umple) Meta-Model Umple was not available, so issues arose between the developer transcribing the model and the model itself
Umple Data Flow Each hand-off is tested individually, as well as within each individual output
TDD Philosophy http://cc.umple.org
Continuous Integration and Deployment http://qa.umple.org http://cc.umple.org
Benefits of Umple • Used in production systems • Umple developed in itself (60+ developers) • Empirical Studies • Umple code is easier to understand than Java • Helps students learn to model: CSEE&T
Production Examples (PHP) Model your PHP applications Moddel layer written in Umple (app/mode) and generates php (app/classes) Integration with existing PHP frameworks like Zend, Slim, CodeIgniter Integration with testing frameworks Works for websites, web applications and restful APIs java -jar ./vendor/umple/umple.jar \ --generate Php \ --path ../classes \ ./app/models/app.ump
Additional Features Generation Templates Concurrency Constraints Patterns Aspect Orientation Tracing http://manual.umple.org
Umple Architecture 1 • Grammar DSL: Online • http://grammar.umple.org • (we migrated from Antlr to better handle embedded code blocks and gain flexibility) • Umple is written in itself • Key to testing and reliability • Github file umple.ump Umple Tutorial
Umple Architecture 2 • Umple’s own class diagram generated by itself from itself: • http://metamodel.umple.org • Colours represent key subsystems • Click on classes to see Javadoc, and then Umple Code Umple Tutorial
Testing:TDD with100% pass always required • Multiple levels: • Parsing tests: basic constructs • Metamodel tests: ensure it is populated properly • E.g. http://code.google.com/p/umple/source/browse/trunk/cruise.umple/test/cruise/umple/compiler/AssociationTest.java • Implementation template tests: to ensure constructs generate code that looks as expected • Testbed semantic tests: Generate code and make sure it behaves the way it should Umple Tutorial