Model-Driven Di Development with ithmagicdraw UML Dr. Darius Silingas Principal MagicDraw UML Trainer/Consultant
Lecturer Dr. Darius Šilingas, darius.silingas@nomagic.comsilingas@nomagic com Principal MagicDraw UML Trainer/Consultant Trained & consulted MagicDraw customers in 17 countries USA, UK, Germany, France, South Africa, Russia, Received Ph.D. in Informatics from Vytautas Magnus University in 2005 Spoke at Architecture & Design World, OOP, JAX Holds the following professional certificates: Microsoft Certified Professional Sun Certified Programmer for the Java 2 Platform 1.4 OMG-Certified UML Professional Advanced 2
Contents UML and Software Development Process Introduction to MagicDraw UML UML Case Study Demo of Selected MagicDraw Features 3
What Is UML? A language (with graphical notation) for modeling object-oriented oriented systems A standard maintained by the Object Management Group (OMG) Provides 249 modeling concepts (meta-classes) and defines 13 diagram types A means for visualizing, specifying, constructing, and documenting systems % of software developers using UML Almost every software development company # of UML tools available ~10 really mature UML tools MagicDraw, Rational Architect, Enterprise Architect, Artisan Studio, Together/J, Objecteering, ~100 less mature UML tools, focusing on fragments of UML http://www.uml.org 4
Using UML in Software Workflows Domain concepts and relations Package/component structure Domain object lifecycle Interaction scenarios Business processes Data structure Actors and use cases Service API Use cases scenarios GUI navigation schemas Test case action flows Test data object structures Interactions for test scenarios Code generation from UML Visualization of code structure Model transformations 5
Choice of Tools? 6
Informal Modeling vs. Using UML Tool Informal Modeling Using UML Tool Easy to start Reusable model repository Very useful for brainstorming Model analysis tools No need to buy tools Model 2 code transformations Difficult to maintain Teamwork possibility Allows deviations from standard Learning to use tool Reuse is not possible Need to invest into buying the tool 7
What is MagicDraw UML? A visual UML modeling editor Domain-Specific Language (DSL) engine A roundtrip code engineering g tool Business process modeling tool A UML model teamwork control system (using Teamwork Server) System documentation tool (using the built-in and custom reports) A modeling environment and model repository for Enterprise Architecture and Model-Driven Architecture paradigms Developed since 1998 second oldest UML tool in the market! Sold in >70 countries, used in different business domains Widely regarded as the most standard-complient UML tool 8
Major MagicDraw UML Concepts Project Options 1 properties Project 1..* modules data 1 Model 0..* codesets Code Engineering Set diagrams 0..* Diagram diagram 1 symbols 0..* Symbol views 0..* data 1 elements 0..* Element modelelements 0..* dependencies 0..* Code File codeelements 0..* 0..* usages 1 properties 1 properties 1 properties Diagram Properties Symbol Properties Specification 9
MagicDraw Differentiation from Other UML Tool Most compliant to the standard High modeling productivity Highly configurable and extendible Free technical support Best value for the price 10
A Case Study for Various Validation Rule Examples 1. An university needs a system MagicTest, which automates test assessments. 2. Teachers specify and maintain questions. 3. Each question must be applicable for 1 or more courses. 4. A question can be closed or open. 5. A closed question defines an ordered set of answer options, where at least one answer option is correct and at least one is incorrect. 6. An open question defines an expected correct answer. 7. Teachers define tests for particular classes that they are running. 8. A test collects a number of questions. 9. A test author also specifies test title, instructions, and allowed time. 10. Students participate in test assessments by providing answers to test questions. 11. MagicTest calculates test assessment evaluations. 12. Data about teachers, students, courses and classes are provided by University Data System (UDS). CHECK OUT MagicTest.mdzip MODEL for ARTEFACTS 11
Current MagicDraw UML Functionalities Model Repository Graphical Diagramming Model Analysis Tools Search/Replace Find/Display Related Elements Calculate Metrics Define Dependency Matrices Configuration User Perspective Environment Options Project Options Environment Extendibility Open API Fragments of AMI Custom Reports Project Decomposition Projects & Modules Model Validation Using OCL or Java Teamwork Server Modeling in Teams DSL Engine Define custom modeling languages Project Version Management Branching, comparison, merge Model Reports Based on user-defined templates Code Engineering Generate code or reserve model 12
Model Validation Created models may be incorrect or incomplete You can define validation rules in OCL and validate model against them 13
Model Analysis Tools Generating Relationship Matrix Finding model element Dependencies/Usages Calculating model metrics Comparing two versions of model data structures and diagrams AudioRecord Book Category Item ItemState Loan Penalty Reader Request Reservation ReservationState e Title TitleCollection UserProfile VideoRecord entity AudioRecord Book Category Item ItemState Loan Penalty Reader Request Reservation ReservationState Title TitleCollection UserProfile VideoRecord 1 1 1 5 1 3 2 4 3 5 1 9 2 1 1 14
Comparison of Model Data Structure Versions Added element Deleted elements Modified element a diagram 15
Comparison of Diagram Versions Find out modified parts in diagrams! 16
Merging Two Model Versions 17
Modeling Teamwork Global l project repository Projects Users Permissions Collaboration inside a project Locking/unlocking model elements Seeing who has locked which elements Submitting changes Change management age e Versioning Branching Comparing Merging 18
Model Transformations Model 2 Code using Code Engineering i Sets Model 2 Model using plug-in Transformations Model 2 Document using Report Wizard with Templates Concept #forrow ($class in $sorter.sort($class, name )) $report.geticonfor($class) $class.name Description $report.getcomment($class) #endrow Concept Reader Request Description Information about library customer. Document registering reader's wish to have a new title in a library. Request est Evaluation ation Librarian's ian's decision whether to approve or deny reader's request. Title Information about a book, journal or another kind of library inventory item. Library may contain multiple l copies of the same title. 19
Model Patterns Apply classic GoF patterns Apply behavioral patterns Reuse predefined model fragments from libraries Title pre-loop action -name : String -publishedat : date -author : String -children 0..* Entry Composite State Inner State A in-loop action TitleCollection Inner State B +add( comp : Title ) +remove( comp : Title ) +getchild( index : int ) : Title [last item] post-loop action [next item] Exit A Exit B 20
Source Code Analysis Using UML You can analyze source code structure using UML as visualization Model can be reversed from source code using reverse engineering tools UML tools include model visualization tools that help to create diagrams from reversed model quickly For model analysis, it is common to use dependency diagrams Possibility to track related elements Calculation of various code analysis metrics EXERCISE: Try out reverse engineering and analyzing JUnit framework 21
Top-Level Package Dependency Diagram for JUnit Framework junit textui swingui awtui Presentation Layer runner framework extensions Execution Core Additions 22
Overview of JUnit Package junit.framework framework (junit) Assert... Test AssertionFailedError TestCase TestSuite ComparisonFailure TestFailure TestResult TestListener t Protectable t...... 23
Core JUnit Classes Assert (junit.framework) +asserttrue( b : boolean ) : void +assertfalse( b : boolean ) : void +fail( string : String ) : void +fail() : void +assertequals( object : Object, object1 : Object ) : void +assertequals( f : float, f1 : float, f2 : float ) : void +assertequals( b : boolean, b1 : boolean ) : void +assertequals( i : int, i1 : int ) : void +assertnotnull( object : Object ) : void +assertnull( object : Object ) : void +assertsame( object : Object, object1 : Object ) : void +assertnotsame( object : Object, object1 : Object ) : void... Test (junit.framework) +counttestcases() : int +run( testresult : TestResult ) : void -ftests 0..* TestCase (junit.framework) +TestCase() +TestCase( string : String ) +counttestcases() : int +run( testresult : TestResult ) : void... TestSuite (junit.framework) +TestSuite() +TestSuite( string : String ) +addtest( test : Test ) : void +addtestsuite( class : Class ) : void +counttestcases() : int +run( testresult : TestResult ) : void... 24
Model-Driven Architecture Model-driven di architecture t (MDA)i is a software design approach for the development of software systems. It provides a set of guidelines for the structuring of specifications, which are expressed as models. Model-driven architecture is a kind of domain engineering, and supports model-driven engineering of software systems. It was launched by the Object Management Group (OMG) in 2001. http://www.omg.org/mda org/mda http://en.wikipedia.org/wiki/model org/wiki/model-driven_architecture 25
Data Modeler s Bermuda Triangle Objects Relational databases XML schemas 26
Applying MDA to Data Design Domain ER model (concepts and relationships) OO data model (classes, attributes, types, associations) Manual transformation Design solutions Semi-automated transformation UML DDL-specific UML UML XSD-specific UML Relational Schema model (tables & keys complex types & attributes) Automated transformation DDL-specific UML DDL XSD-specific UML XSD DDL XSD code (DDL script XML schema specification) 27
Case Study: Domain ER Model Reader submits Reservation fulfills Loan 1 * 1 0..1 * * books 1 issues 1 Category is assigned to Title is instance of Item 1..* * 1 * 28
Case Study: Object-Oriented Data Model Reader Reservation Loan id : Integer active : Boolean name : String email : String author 1 madeat : date pendingfrom : date status : Integer reservation 1 madeat : date returnedat : date dueat : date reservedtitle 1 loaneditem 1 Category Title 0..1 Item name : String categories name : String assigneditem nr : Integer description : String 1..* author : String title status : Integer publishedat : date 1 0..* Book isbn : String pages : Integer MediaRecord duration : Integer tracks : String 29
Case Study: DDL-Specific Model <<table>> Reader <<table>> Reservation <<table>> Loan <<PK>>id : integer active : Boolean name : varchar email : varchar <<FK>> <<PK>>id : integer madeat : date pendingfrom : date status : integer fkreader : integer [1] fktitle : integer [1] <<FK>> <<PK>>id : integer madeat : date returnedat : date dueat : date fkitem : integer [1] fkreservation : integer [1] <<FK>> <<FK>> <<FK>> <<table>> CategoryTitle fkcategory : integer fktitle : integer <<FK>> <<table>> Title <<PK>>id : integer name : varchar author : varchar publishedat : date <<FK>> <<table>> Item <<PK>>id : integer nr : integer status : integer fktitle : integer [1] fkreservation : integer [1] <<FK>> <<FK>> <<FK>> <<table>> Category <<table>> Book <<table>> MediaRecord <<PK>>id : integer name : varchar description : varchar <<PK>>id : integer isbn : varchar pages : integer <<PK>>id : integer duration : integer tracks : varchar 30
Case Study: DDL Script (Fragment) CREATE TABLE Reservation ( id integer PRIMARY KEY, madeat date, pendingfrom date, status s integer, fkreader integer NOT NULL, fktitle integer NOT NULL, FOREIGN KEY(fkTitle) REFERENCES Title(id), FOREIGN KEY(fkReader) REFERENCES Reader(id)); 31
Case Study: XSD-Specific Model <<XSDcomplexType>> <<XSDelement>> <<XSDcomplexType>> <<XSDelement>> <<XSDsequence>> author <<XSDsequence>> reservation Reader 1 0..* Reservation 1 0..* id : integer madeat : datetime active : Boolean pendingfrom : datetime name : string status : integer email : string <<XSDcomplexType>> <<XSDsequence>> Loan madeat : datetime returnedat : datetime dueat : datetime <<XSDcomplexType>> <<XSDsequence>> Category name : string description : string <<XSDelement>> categories 1..* 0..* <<XSDelement>> reservedtitle 1 <<XSDcomplexType>> <<XSDsequence>> Title name : string author : string publishedat : datetime <<XSDelement>> loaneditem 1 <<XSDelement>> <<XSDcomplexType>> assigneditem <<XSDsequence>> 0..1 Item <<XSDelement>> title nr : integer status : integer 1 0..* <<XSDextension>> <<XSDcomplexContent>> <<XSDcomplexType>> <<XSDsequence>> Book isbn : string pages : integer <<XSDextension>> <<XSDcomplexContent>> <<XSDcomplexType>> <<XSDsequence>> MediaRecord duration : integer tracks : string 32
Case Study: XML Schema (Fragment) <xs:complextype name="reservation"> <xs:sequence> <xs:element maxoccurs="1" name="author" type="reader"/> <xs:element maxoccurs="1" name="reservedtitle" type="title"/> <xs:element maxoccurs="1" minoccurs="0" name="assigneditem" type="item"/> </xs:sequence> <xs:attribute name="madeat" type="xs:datetime"/> <xs:attribute name="pendingfrom" type="xs:datetime"/> <xs:attribute name="status" type="xs:integer"/> </xs:complextype> 33
Thank You for Attention! Questions??? Let s Keep in Touch: Dr. Darius Šilingas E-mail: darius.silingas@nomagic.com Skype: darius.silingas Phone: +370 37 705899 34