Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © IBM Corp., 2007-2008. | March-17-2008 | Creating Robust Scalable DSLs with UML Tutorial (172) James Bruck, Christian Damus IBM Rational Software.

Similar presentations


Presentation on theme: "Copyright © IBM Corp., 2007-2008. | March-17-2008 | Creating Robust Scalable DSLs with UML Tutorial (172) James Bruck, Christian Damus IBM Rational Software."— Presentation transcript:

1 Copyright © IBM Corp., 2007-2008. | March-17-2008 | Creating Robust Scalable DSLs with UML Tutorial (172) James Bruck, Christian Damus IBM Rational Software

2 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 2 Agenda Introduction Exploring Extension Mechanisms  Featherweight  Lightweight  Middleweight  Heavyweight Deciding which Technique to Use Advanced Concepts  Subsetting  Derived Unions  Redefinition Meta-model Decomposition  Package Merge  Language Units  Compliance Levels Summary

3 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 3 Introduction – What is a DSL? DSL stands for “Domain Specific Language”. A DSL is created specifically to solve problems in a particular domain.  A language designed to be useful for a specific task. UML® is a general purpose modeling language.  Large and very expressive.  UML 1.x was sometimes criticized for being too large, UML 2.x adds even more concepts.

4 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 4 Introduction – Why extend UML? A common end-goal of those wishing to extend UML is to leverage existing tools and conventions defined by UML while making modeling easier for the end user.  Give a terminology that is adapted to a particular domain.  Give a different notation for already existing symbols  Add semantics that do not exist in the meta-model.  Add constraints that restrict the way you use the meta-model.  Add information that can be used when transforming a model to another model or code.

5 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 5 Introduction – Understanding the Options Need to know:  The types of customizations you wish to create.  Add/remove behavior  Add/remove properties  Add/remove constraints  How the extended meta-model is intended to be used.  How will end user create instances of new meta-types and meta- types from the extended meta-model.  How much overlap exists between new domain and extended domain.

6 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 6 Agenda Introduction Exploring Extension Mechanisms  Featherweight  Lightweight  Middleweight  Heavyweight Deciding which Technique to Use Advanced Concepts  Subsets  Derived Unions  Redefinition Meta-model Decomposition  Package Merge  Language Units  Compliance Levels Summary

7 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 7 Exploring Extension Mechanisms - Featherweight Why use Keywords?  To distinguish a particular concept from others sharing the same general graphical form. For example:  uml::Interface has a similar appearance to uml::Class. The keyword > is used to distinguish interfaces from other classifiers.

8 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 8 Exploring Extension Mechanisms - Featherweight Why use Keywords?  To distinguish a particular kind of relationship from other relationships sharing the same graphical form.

9 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 9 Exploring Extension Mechanisms - Featherweight Why use Keywords?  To specify the value of some modifier attached to a meta-attribute value.  The keyword > appearing within an Activity signifies that the isSingleExecution attribute of the Activity is true.  To indicate standard stereotype.  For example the > keyword attached to a package identify that the package contains a set of model elements intended to be shared by multiple models. There is support in the API:  Element::addKeyword(), Element::removeKeyword(), Element::hasKeyword() etc.

10 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 10 Exploring Extension Mechanisms - Featherweight Pro  Adding keyword is trivial  Great to visually distinguish items Con  Limited functionality  Cannot add attributes or operations

11 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 11 Agenda Introduction Exploring Extension Mechanisms  Featherweight  Lightweight  Middleweight  Heavyweight Deciding which Technique to Use Advanced Concepts  Subsets  Derived Unions  Redefinition Meta-model Decomposition  Package Merge  Language Units  Compliance Levels Summary

12 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 12 Exploring Extension Mechanisms - Lightweight A profile defines a limited extension to a reference meta-model. Primary extension construct is the Stereotype. Stereotypes can be used to add:  Keywords  Constraints  Images  Properties  Behavior Should be your first choice when considering extending UML.

13 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 13 Exploring Extension Mechanisms - Lightweight

14 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 14 Exploring Extension Mechanisms - Lightweight Pro  Easy to create and work with.  Well described and documentation in the superstructure spec.  Standard means to define icons and display options.  Low implementation cost.  Standard mechanism that interoperates with other compliant tools. Con  Cannot remove existing constraints.  Cannot modify existing structures.  Not a first class extension mechanism.  Cannot use redefinition for example since Stereotypes are not specializations of the meta-types they extend.

15 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 15 Exercise 1 – Lightweight Extension Objectives:  Learning how to describe domain specific constructs with a profile.  Explore Static Profile Definition.  Generate Java™ API for the profile.  Register the generated profile to make it available at run-time.  Work with your profile.  Apply and use the profile in a UML model.

16 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 16 Exercise 1 – Lightweight Extension Core stereotypes of the MyUnit profile.

17 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 17 Exercise 1 – Lightweight Extension Timing stereotypes of MyUnit profile  For performance sensitive tests

18 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 18 Agenda Introduction Exploring Extension Mechanisms  Featherweight  Lightweight  Middleweight  Heavyweight Deciding which Technique to Use Advanced Concepts  Subsets  Derived Unions  Redefinition Meta-model Decomposition  Package Merge  Language Units  Compliance Levels Summary

19 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 19 Exploring Extension Mechanisms - Middleweight Extension by specialization of UML meta-classes.  Extend byspecializing types within UML.metamodel.uml (the merged UML meta-model) Creating dependencies on a specific version of UML. Implementation classes in the specialized meta-model reference internal UML implementation classes (compiler warnings)

20 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 20 Exploring Extension Mechanisms - Middleweight Pro  First class extension mechanism.  Easier than heavyweight to create initially.  Easy for end user to use programmatically than profiles.  Can add behavior.  Can add structure.  Can add constraints. Con  Creates dependence on specific version of UML.  Difficult to maintain especially if UML changes.  User must know about 2 factories for creating elements, the UMLFactory and the new one defined by the extension.

21 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 21 Agenda Introduction Exploring Extension Mechanisms  Featherweight  Lightweight  Middleweight  Heavyweight Deciding which Technique to Use Advanced Concepts  Subsets  Derived Unions  Redefinition Meta-model Decomposition  Package Merge  Language Units  Compliance Levels Summary

22 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 22 Exploring Extension Mechanisms – Heavyweight Reuse by copy instead of reuse by extension as middleweight. Heavyweight extensions involve 2 steps  Select the language units you wish to extend and merge.  Add your own domain specific types. Merging packages forms the basis for constructing UML itself. Have access to all concepts used to create UML  Subset  Redefinition  Derived unions

23 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 23 Exploring Extension Mechanisms – Heavyweight Pro  Easy for end users to use programmatically (only 1 meta-model in the end)  Ability to override or customize operations and behavior.  Can add behavior/constraints/structure.  Isolate yourself from changes to UML meta-model.  You can stratify your own specialized meta-model for different levels of abstraction and DSL concerns. Con  Costly development (more complex than profiles).  Difficult to maintain (re-merge).  Lose interoperability with other UML based tools since we have a new meta-model.

24 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 24 Agenda Introduction Exploring Extension Mechanisms  Featherweight  Lightweight  Middleweight  Heavyweight Deciding which Technique to Use Advanced Concepts  Subsets  Derived Unions  Redefinition Meta-model Decomposition  Package Merge  Language Units  Compliance Levels Summary

25 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 25 Other concepts – Subsets Comes in 2 flavors  Derived subsets  Non-derived subsets UML2 includes a customized EMF code generator to handle subsets.

26 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 26 Other concepts – Subsets - Derived Values are computed from the values of the superset property.  Often read-only. Example  Package::nestedPackage is a derived subset of Package::packageableElement.  Since nested package collection is derived, a user cannot add directly to it.  Clients must add to the packageableElement collection.

27 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 27 Other concepts – Subsets – Non-Derived Values are not computed from the superset values.  Must be writable. Example  Operation::precondition subsets Namespace::ownedRule.  Adding a precondition to some operation means that if you call Operation::getOwnedRules(), that precondition will appear in the collection.  A precondition has a “Subset-Superset” implementation meaning that if a Constraint was added to owned rule collection that it would not be added to precondition list. However, adding to the precondition collection does mean that it gets added to the owned rule collection.

28 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 28 Other concepts – Derived unions Indicate that a property is the union of one or more collections (or scalar). Typically applied to properties on abstract types high up in the inheritance hierarchy. Concrete types make a derived union useful by contributing subsets. Derived unions are read only and derived ( ).

29 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 29 Other concepts – Derived unions Element::ownedElement is a derived union.  Element contributes Element::ownedComment to that collection.  Package contributes Package::ownedTemplateSignature and Package::profileApplication amongst others.

30 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 30 Derived unions: Example

31 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 31 Other concepts – Redefinition Redefinition replaces an existing property. Redefinition only makes sense in the context of specialization. May be used to change the definition of a feature. The detailed semantics of redefinition vary for each specialization of RedefinableElement in UML.

32 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 32 Other concepts – Redefinition Redefinition can be used to restrict the kinds of things added to a collection (like co-variant returns in Java™). The name of a property which has been redefined does not have to match the one redefining it.

33 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 33 Other concepts – Redefinition: Example Class::superClass redefines Classifier::general

34 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 34 Exercise 2 – Creating Middleweight Extension Objectives:  Explore subsets.  Explore extending UML using specialization.  Explore code generator options.

35 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 35 Exercise 2 – Creating Middleweight Extension Core meta-classes of the MyUnit meta-model.

36 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 36 Exercise 2 – Creating Middleweight Extension Timing meta-classes of the MyUnit meta-model

37 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 37 Agenda Introduction Exploring Extension Mechanisms  Featherweight  Lightweight  Middleweight  Heavyweight Deciding which Technique to Use Advanced Concepts  Subsetting  Derived Unions  Redefinition Meta-model Decomposition  Package Merge  Language Units  Compliance Levels Summary

38 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 38 Package Merge A directed relationship between two packages which indicates that the contents are to be combined. This mechanism should be used when elements defined in different packages are intended to represent the same concept. By selecting which increments to merge, it is possible to obtain a custom definition of a concept. Package merge allows modeling concepts defined in one package to be extended with new features. UML itself is a merge of a large number of packages.

39 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 39 Package Merge Package merge allows modeling concepts defined at one level to be extended with new features.

40 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 40 Package Merge - Example

41 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 41 Language Units In order to deal with the problem of language complexity, UML 2.0 was modularized in a way that allows selective use of language units. The modeling concepts in UML are also partitioned into layers of capability referred to as compliance levels. UML itself is ultimately merged into a single package which defines a shared namespace for all compliance levels.

42 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 42 Language Units and Compliance Levels

43 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 43 Compliance Levels – L0 Represents a common denominator that can serve as a basis for interoperability. The core of EMOF.

44 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 44 Compliance Levels – L1 Adds language units for use cases, interactions, structures, actions, and activities.

45 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 45 Compliance Levels – L2 Adds language units for deployment, state machine modeling and profiles.

46 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 46 Compliance Levels – L3 Adds language units for information flows, templates and model packaging. Represents the complete UML.

47 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 47 Exercise 3 – Creating Heavyweight Extension Objectives:  Explore Package Merge.  Explore working with your extension (generating an editor).

48 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 48 Exercise 3 – Creating Heavyweight Extension Core package of the MyUnit library

49 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 49 Exercise 3 – Creating Heavyweight Extension Timing Language UnitObjectives Language Unit

50 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 50 Exercise 3 – Creating Heavyweight Extension Overview of the MyUnit library

51 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 51 Exercise 3 – Creating Heavyweight Extension Basic Compliance LevelComplete Compliance Level

52 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 52 Agenda Introduction Exploring Extension Mechanisms  Featherweight  Lightweight  Middleweight  Heavyweight Deciding which Technique to Use Advanced Concepts  Subsets  Derived Unions  Redefinition Meta-model Decomposition  Package Merge  Language Units  Compliance Levels Summary

53 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 53 Summary Four basic techniques.  Flyweight  Lightweight  Middleweight  Heavyweight Favor “lightweight” extension (use of profiles).  A practical solution for most applications.

54 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 54 Thank You!

55 Creating Robust Scalable DSLs with UML | Tutorial | Copyright © IBM Corp., 2007-2008. All rights reserved. 55 Legal Notices Copyright © IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0; remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license. IBM and the IBM logo are trademarks or registered trademarks of IBM Corporation in the United States, other countries, or both. Rational and the Rational logo are trademarks or registered trademarks of International Business Corporation in the United States, other countries, or both. UML, Unified Modeling Language, and MOF are trademarks or registered trademarks of Object Management Group, Inc. Java and all Java-based trademarks, among others, are trademarks or registered trademarks of Sun Microsystems in the United States, other countries, or both Eclipse and the Eclipse logo are trademarks of the Eclipse Foundation, Inc. Other company, product, and service names may be trademarks or service marks of others. THE INFORMATION DISCUSSED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY. WHILE EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION, IT IS PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, AND IBM SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE RELATED TO, SUCH INFORMATION. ANY INFORMATION CONCERNING IBM’S PRODUCT PLANS OR STRATEGY IS SUBJECT TO CHANGE BY IBM WITHOUT NOTICE.


Download ppt "Copyright © IBM Corp., 2007-2008. | March-17-2008 | Creating Robust Scalable DSLs with UML Tutorial (172) James Bruck, Christian Damus IBM Rational Software."

Similar presentations


Ads by Google