UML UML 2 0 tutorial n Ileana Ober
UML / UML 2. 0 tutorial n Ileana Ober n IRIT – UPS, Toulouse, France n http: //www. irit. fr/~Ileana. Ober 1
UML tutorial – Ileana Ober Modeling in the ’ 80 – ’ 90 s n Lots of (slightly different) languages and design techniques OMT n Coad & Yourdon n BON n SDL n ROOM n Shlaer Mellor n … Quite a mess ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 2
UML tutorial – Ileana Ober In use with permission from PIB Copenhagen A/S, obtained august 2005 ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 3
UML tutorial – Ileana Ober UML n Sought as a solution to the OOA&D mess n Aims at n Unifying design languages n Being a general purpose modeling language Lingua franca of modeling ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 4
UML tutorial – Ileana Ober Overview n What is UML? n Structure description n Behavior description n OCL n UML and tools ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 5
UML tutorial – Ileana Ober UML (Unified Modeling Language) n Goal: lingua franca in modeling n Definition driven by consensus rather than innovation n Definition style: Described by a meta-model (abstract syntax) n Well formedness rules in OCL n Textual description n n static and dynamic semantics (in part already described by WFRs) notation description usage notes ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 6
UML tutorial – Ileana Ober Overview of the 13 diagrams of UML Structure diagrams 1. Class diagram 2. Composite structure diagram (*) 3. Component diagram 4. Deployment diagram 5. Object diagram 6. Package diagram Behavior diagrams 7. Use-case diagram 8. State machine diagram 9. Activity diagram Interaction diagrams 10. 11. 12. 13. Sequence diagram Communication diagram Interaction overview diagram (*) Timing diagram (*) not existing in UML 1. x, added in UML 2. 0 ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 7
UML tutorial – Ileana Ober UML principle: diagram vs. model n Different diagrams describe various facets of the model n Several diagrams of the same kind may coexist n Each diagram shows a projection of the model n Incoherence between diagrams (of the same or of different kind(s)) correspond to an ill-formed model n The coherence rules between different kinds of diagrams is not fully stated ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 8
UML tutorial – Ileana Ober This tutorial looks closer at … n Use case diagram n Class diagram n Composite structure diagram n Component/deployment diagram n State machine diagram n Activity diagram n Interaction diagrams ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 9
UML tutorial – Ileana Ober Overview n What is UML? n Structure description n Use case diagram n Class diagram n Composite structure diagram n Communication principles in UML n System initialization n Behavior description n OCL n UML and tools ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 10
UML tutorial – Ileana Ober Use case diagram n Displays the relationship among actors and use cases, in a given system n Main concepts: n System – the system under modeling n Actor – external “user” of the system n Use case – execution scenario, observable by an actor ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 11
UML tutorial – Ileana Ober Use case diagram example UMLModeling. Project 1 ARTIST Summer School Website Participant Check. Program Update. Program Organizer <<include>> Update. Info Lecturer ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 12
UML tutorial – Ileana Ober Use case diagram – final remarks n Widely used in real-life projects n Used at: n Exposing requirements n Communicate with clients n Planning the project n Additional textual notes are often used/required n User-centric, non formal notation n Few constraints in the standard Further reading: D. Rosenberg, K. Scott Use Case Driven Object Modeling with UML : A Practical Approach, Addison-Wesley Object Technology Series, 1999 I. Jacobson, Object-Oriented Software Engineering: A Use Case Driven Approach, Addison. Wesley Professional, 1999 Writing Effective Use Cases Alistair Cockburn Addison-Wesley Object Technology Series, 2001 ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 13
UML tutorial – Ileana Ober Overview n What is UML? n Structure description n Use case diagram n Class diagram n Composite structure diagram n Communication principles in UML n System initialization n Behavior description n OCL n UML and tools ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 14
UML tutorial – Ileana Ober Class diagram n The most known and the most used UML diagram n Gives information on model structural elements n Main concepts involved Class - Object n Inheritance n Association (various kinds of) n ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 15
UML tutorial – Ileana Ober Let’s start with … object orientation n Why OO? In the first versions, UML was described as addressing the needs of modeling systems in a OO manner n Statement not any longer maintained, however the OO inspiration for some key concepts is still there n Main concepts: n n Object – individual unit capable of receiving/sending messages, processing data Class – pattern giving an abstraction for a set of objects Inheritance – technique for reusability and extendibility Further reading: Bertrand Meyer: Object-Oriented Software Construction, 2 nd edition, Prentice Hall, 2000 ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 16
UML tutorial – Ileana Ober UML Class n Gives the type of a set of objects existing at run-time n Declares a collection of methods and attributes that describe the structure and behavior of its objects n Basic notation: Automobile wheels. NO : integer serial. No : integer fill. Tank() ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 17
UML tutorial – Ileana Ober Properties of UML classes n May own features n Structural (data related) : attributes n Behavioral : operations n May own behavior (state machines, interactions, …) n May be instantiated n except for abstract classes that can NOT be directly instantiated and exist only for the inheritance hierarchy ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 18
UML tutorial – Ileana Ober Class features – characterized by n Signature n Visibility (public, private, protected, package) n Changeability (changeable, frozen, add. Only) n Owner scope (class, instance) – equivalent to static clause in programming languages n Invariant constraint n Additionally, operations are characterized by n concurrency kind: sequential, guarded, concurrent n pre or post conditions n body (state machine or action description) ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 19
UML tutorial – Ileana Ober Decode class symbol adornments Class name in italics: abstract class Underlined attribute = class attribute Feature visibility +, -, #, ~ Simple class box: passive class Vehicle Door 0. . 1 * door Attributes area Automobile +wheels. NO : integer -serial. No : integer +fill. Tank(In volume: real): real Operations area ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 20
UML tutorial – Ileana Ober Active / passive classes n specifies the concurrency model for classes n specifies whether an Object of the Class maintains its own thread of control and runs concurrently with other active Objects (active) Thick box: active class ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 21
UML tutorial – Ileana Ober Object n Instance of a class n Can be shown in a class diagram n Notation ford : Automobile wheels. NO=4 serial. No=123 ABC 567 D ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 22
UML tutorial – Ileana Ober Inheritance n A. k. a. generalization (specialization) n Applies mainly on classes n Other UML model elements can be subject to inheritance (e. g. interface) (if you want the exact list go check the UML metamodel for kinds of Generalizable. Elements) n Allows for polymorphism ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 23
UML tutorial – Ileana Ober Inheritance/polymorphism example Animal a; Cow cw; Cat ct; …. . if (<condition>) a: = cw else a: = ct endif Animal cry() Cat Cow cry(){mooo} cry(){meow } a. cry() --- should be a mooo or a meow depending on the <condition> ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 24
UML tutorial – Ileana Ober Association n Concept with no direct equivalent in common programming languages n Is defined as a semantic relationship between classes, that can materialize at runtime n The instance of an association is a set of tuples relating instances of the classes n It’s actual nature may vary, in terms of code, they may correspond to n n n Attributes, pointers Operations Graphical comments ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 25
UML tutorial – Ileana Ober Example Association end Person driver car 0. . 1 * passenger Automobile +wheels. NO : integer serial. No : integer +fill. Tank(In volume: real): real 1 vehicle Uses. Vehicle ► Association symbol ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 26
UML tutorial – Ileana Ober Example – at instance level driver car john : Person 9999 : Automobile passenger driver vehicle car mary : Person passenger 1111 : Automobile vehicle tom : Person vehicle passenger Link symbol ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 27
UML tutorial – Ileana Ober Example – at instance level driver car john : Person 9999 : Automobile passenger driver vehicle car mary : Person passenger 1111 : Automobile vehicle tom : Person vehicle passenger Note on style in UML diagrams: Instance level names: lower case Type level names: upper case ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 28
UML tutorial – Ileana Ober Association end n Endpoint of an association n Characterized by a set of properties contributing to the association definition Multiplicity (ex: 1, 2. . 7, *, 4. . * ) n Ordering ordered/unordered n Visibility +, -, #, ~ n Aggregation… n ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 29
UML tutorial – Ileana Ober Various kinds of associations (1/2) n Regular association n Composition: one class is owned (composed in) the associated class Composition implies lifetime responsibility (based on association end multiplicities) Vehicle Door 0. . 1 *door Automobile Composition symbol +wheels. NO : integer -serial. No : integer +fill. Tank(In volume: real): real ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 30
UML tutorial – Ileana Ober Various kinds of associations (2/2) n Aggregation “light” composition, semantics left child Person open, to be accommodated to user needs * parent 2 As it is, it has no particular * owner meaning… aggregation symbol Further reading: F. Barbier, B. Henderson-Sellers, A. Le Parc-Lacayrelle, J. -M. Bruel: Formalization of the Whole-Part Relationship in the Unified Modeling Language, IEEE Transactions on Software Engineering, 29(5), IEEE Computer Society Press, pp. 459 -470, 2003 ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 pet* Dog 31
UML tutorial – Ileana Ober More on associations… n Associations may be n-ary (n>2) n Qualifiers – partition the set of objects that may participate in an association owner * Person owner 0. . 1 same relationship * account Bank. Account account. No ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 32
UML tutorial – Ileana Ober Association class n An association that is also a class. n It defines a set of features that belong to the relationship itself and not any of the classifiers. Person driver 0. . 1 car owned. Car 1 association class symbol Automobile wheels. NO : integer * serial. No : integer fill. Tank() Car. Papers license. No : integer registry: Date ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 33
UML tutorial – Ileana Ober Other elements of class diagrams n Interface (definition and use) n Comments ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 34
UML tutorial – Ileana Ober Interface n Declares set of public features and obligations n Specifies a contract, to be fulfilled by classes implementing the interface n Not instantiable n Its specification can be realized by 0, 1 or several classes n n the class presents a public facade that conforms to the interface specification (e. g. interface having an attribute does not imply attribute present in the instance) a class may implement several interfaces n Interfaces hierarchies can be defined through inheritance relationships ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 35
UML tutorial – Ileana Ober Interface definition and use examples <<interface>> Interaction. Primitives Satellite Secure. Interaction token. Exchange() <<interface>> Secure. Interaction The class Satellite provides implementation for the 3 operations check. Consistency() retrieve. Last() ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 36
UML tutorial – Ileana Ober Means to specify the interface contract n Invariant conditions n Pre and post conditions (e. g. on operations) n Protocol specifications which may impose ordering restrictions on interactions through the interface for this one may use protocol state machines ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 37
UML tutorial – Ileana Ober Templates n Mechanism for defining patterns whose parameters represent types n It applies to classifiers, packages, operations n A template class is a template definition n Cannot be instantiated directly, since it is not a real type n Can be bound to an actual class by specifying its parameters n A bound class is a real type, which can be instantiated ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 38
UML tutorial – Ileana Ober Template example T, k: Integer TList element : T[k] insert(p: T) remove(p: T) <<bind>> <Lecture, 14> Lecture. List element : Lecture[14] ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 39
UML tutorial – Ileana Ober Class diagram summary n One of the most used diagrams n Describes the static structure of the system in terms of classes and their relationships (associations, inheritance) n Offers connection points with the UML behavior description means ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 40
UML tutorial – Ileana Ober Overview n What is UML? n Structure description n Use case diagram n Class diagram n Components n Communication principles in UML n System initialization n Behavior description n OCL n UML and tools ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 41
UML tutorial – Ileana Ober Component n Its definition evolves from UML 1. x to UML 2. 0 n In UML 1. x - deployment artifacts <<component>> compiler. jar n In UML 2. 0 – structured classes ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 42
UML tutorial – Ileana Ober Component in UML 2. 0 n Modular part of a system encapsulating its content n Defines its behavior in terms of provided and required interfaces, and associated contracts n Defines a type. Type conformance is defined on the basis of conformance to provided / required interfaces n Main property: substitutability = ability to transparently replace the content (implementation) of a component, provided its interfaces and interface contract are not modified ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 43
UML tutorial – Ileana Ober Component examples (1/2) n Algorithmic calculus component n Interface: n n n Offered: provided mathematical calculus functions Required : logarithm value calculus Contract n n Expected behavior Constraints on unauthorized values ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 44
UML tutorial – Ileana Ober Component examples (2/2) : mobile phone logical network Sample component: virtual cell manager n Interface: n n n Manage reachable mobile phones Forward message calls … n Contracts: n Functional n Fulfill expected behavior n Protocol describing authorized message exchange: (e. g. first identify) n Non-functional n Net load capacity, reactivity time, electromagnetic interference… ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 45
UML tutorial – Ileana Ober Component related concepts n Class n Package n (Library) The exact relationship between all these concepts is not completely clear (neither in UML, nor in the literature) ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 46
UML tutorial – Ileana Ober UML offers a unifying concept… classifier n Generalization of the class concept n Gives a type for a collection of instances sharing common properties n Interfaces, classes, data types, components ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 47
UML tutorial – Ileana Ober Composite structure diagram (a. k. a. architecture diagram) n Added in UML 2. 0 n Depicts n The internal structure of a classifier n Interaction points to other parts of the system n Configuration of parts that perform together the behavior of the containing classifier n Concepts involved: n Classifier n Interface n Connection n Port n Part ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 48
UML tutorial – Ileana Ober Part n Element representing a (set of) instance owned by a classifier n Semantics close to the one of attributes or composed classes May specify a multiplicity n At parent creation time, parts may need to be created also n When the parent is destroyed, parts may need to be destroyed also n ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 49
UML tutorial – Ileana Ober Example ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 50
UML tutorial – Ileana Ober Abstraction level for part n Somewhere between instance and type… n WFL characterizes the wheels front left, owned by Car instances n Given a Car class instance, the part WFL is an instance of its front right wheel n If no Car class instance is fixed, the part WFL is an instance abstraction generically characterizing front right wheels of Cars ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 51
UML tutorial – Ileana Ober Port n feature of a classifier specifying a distinct interaction point n n between that classifier and its environment (service port) between the behavior of the classifier and its internal parts (behavior port) n characterized by a list of required and provided interfaces n n Required interfaces describe services the owning classifiers expect from environment and may access via this interaction point Provided interfaces describe services the owning classifiers offer to its environment via this interaction point n an instance may differentiate between invocations of a same operation received through different ports ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 52
UML tutorial – Ileana Ober Connector n Link enabling communication btw instances n It’s actual realization is not specified (simple pointer, network connection, …) n It has two connector ends, each playing a distinct role n The communication realized over a connector may be constrained (type constraint, logical constraint in OCL, etc) ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 53
UML tutorial – Ileana Ober Communication architecture n complex multiplicity need for initialization rules a 1: A a 2: A 4 2 1 : B 2 b 1: B a 3: A a 4: A b 2: B ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 54
UML tutorial – Ileana Ober Example: composite structure diagram ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 55
UML tutorial – Ileana Ober Port vs. interface n Interface – signature n Port – interaction point n Interfaces describe what happens at a port n The same interface may be attached to several ports of a component ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 56
UML tutorial – Ileana Ober Port constraints vs. interface constraints n Constraints may be attached to both ports and interfaces n For both, constraints can take the form of pre and post conditions, invariants, protocol constraints n Nothing is stated on how constraints at various levels should be composed n By default, constraint conjunction n More elaborated constraint handling schemes may be imposed by the methodology ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 57
UML tutorial – Ileana Ober Connector vs. link n Link = association instance n Data oriented n May be attached to any instance of the corresponding classifier n Connector n Behavior (communication) oriented n Can only be connected to particular instances n Instance to which it applies are depicted in the composite structure diagram ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 58
UML tutorial – Ileana Ober Overview n What is UML? n Structure description n Use case diagram n Class diagram n Components n Communication principles in UML n System initialization n Behavior description n OCL n UML and tools ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 59
UML tutorial – Ileana Ober Communication n Communication primitives n Communication schema ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 60
UML tutorial – Ileana Ober Communication primitives n Signal n n One way Asynchronous communication primitive May carry data It is defined independently of the classifiers handling it n Operation call n n Two-way communication primitive (call-reply) The caller is blocked May carry data Typically, it has a target object n Queue n n n Communication buffer May be attached to instances Management policy not constrained ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 61
UML tutorial – Ileana Ober Signal definition and use examples signal definition <<signal>> Initiate. Call called. No : string <<interface>> Phone. Connection <<signal>> Initiate. Call Mobile. Phone signal integrated in an interface definition Phone. Connection Class implementing the interface Network. Cell Class able to receive a signal <<signal>> Initiate. Call ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 62
UML tutorial – Ileana Ober Communication schema in UML n If the model says noting on communication (i. e. no connectors exist) n n Point to point: between objects knowing their ID (due to existing associations, passed as parameter in some operation, etc) Broadcast: to listening and accessible objects n If a communication structure is stated (architecture diagram) - the communication obeys its constraints communication paths, connectors chain, conveyed messages, port constraints etc… ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 63
UML tutorial – Ileana Ober Overview n What is UML? n Structure description n Use case diagram n Class diagram n Components n Communication principles in UML n System initialization n Behavior description n OCL n UML and tools ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 64
UML tutorial – Ileana Ober System initialization n What it is? n The mechanism that gives the initial status of the system n How it can be done? n Using a God object that creates the whole system n Using an initialization script n Based on a particular object diagram giving the snapshot of the system at initialization time n How it is in the standard? n No standard mechanism exists ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 65
UML tutorial – Ileana Ober Going forward in component based modeling … n The actual “wiring” of components is design using component and deployment diagrams n Component diagrams n n Models business and technical software architecture Uses components defined in the composite structure diagrams, in particular their ports and interfaces n Deployment diagrams n Models the physical software architecture, including issues such as the hardware, the software installed on it and the middleware n Gives a static view of the run-time configuration of processing nodes and the components that run on those nodes ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 66
UML tutorial – Ileana Ober Deployment diagram example Summer. School. Web. Server Subscribe. Application Registered. Students. DB Services <<http>> Terminal. PC Registration. Interface ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 67
UML tutorial – Ileana Ober Overview n What is UML? n Structure description n Behavior description n State machine diagrams n Protocol state machine n Activity diagrams n Sequence diagrams n Timing diagrams n OCL n UML and tools ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 68
UML tutorial – Ileana Ober State machine n UML finite state automaton n Behavior description mechanism n Describes the behavior for: n System n Class n Operation ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 69
UML tutorial – Ileana Ober Specifying behavior in UML ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 70
UML tutorial – Ileana Ober Main concepts n State – stores information of the system (encodes the past) Particular states n n Initial state (? ) Final state n Transition – describes a state change n Can be triggered by an event n Can be guarded by a condition n Actions – behavior performed at a given moment n Transition action : action performed at transition time n Entry action : action performed when entering a state n Exit Action : action performed when exiting a state n Do Action : action performed while staying in a state ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 71
UML tutorial – Ileana Ober Simple state machine example switch/nb=nb+1 On Off switch [nb>250000] ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 72
UML tutorial – Ileana Ober Simple state machine example Triggered transition with action Entry state switch/nb=nb+1 On Off switch Simple state [nb>250000] Guarded transition Exit state ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 73
UML tutorial – Ileana Ober Event n “Specification of some occurrence that may potentially trigger effects by an object” Typically used in State. Machines as triggers on transitions n Examples (as defined in the standard): Signal. Event, Call. Event, Change. Event, Time. Event, etc. n Notion refined in the SPT profile ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 74
UML tutorial – Ileana Ober Hierarchical states n All states are at the same level => the design does not capture the commonality that exists among states n Solution: Hierarchical states – described by sub-state machine(s) n Two kinds of hierarchical states: And-states (the contained sub-states execute in parallel) n Or-states (the contained sub-states execute sequentially) n ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 75
UML tutorial – Ileana Ober Hierarchical OR-state machine example On switch/nb=nb+1 Off cd Radio switch CD radio [nb>250000] ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 76
UML tutorial – Ileana Ober Hierarchical AND-state machine example On cd Radio Off switch/nb=nb+1 [nb>250000] CD radio inc/if v<max then v++ Volume. Manager dec/if dec >0 then dec - - ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 77
UML tutorial – Ileana Ober History sub-states On switch/nb=nb+1 H Off cd Radio switch CD radio [nb>250000] ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 78
UML tutorial – Ileana Ober Semantic nuances in state machine diagrams vs. /* no trigger here */ ev 1 ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 79
UML tutorial – Ileana Ober When to use state machines? n For reactive systems n Why use them? If properly used n easy to read n nice verification results n the tools can generate code more efficient than if hand-written n Open questions: n n state machine inheritance… consensual semantics Further reading: Harel, David and Eran Gery, "Executable Object Modeling with Statecharts", IEEE Computer, July 1997, pp. 31 -42. Harel, David, "Statecharts: A Visual Formalism for Complex Systems", Science of Computer Programming, 8, 1987, pp. 231 -274. ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 80
UML tutorial – Ileana Ober Overview n What is UML? n Structure description n Behavior description n State machine diagrams n Protocol state machine n Activity diagrams n Sequence diagrams n Timing diagrams n OCL n UML and tools ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 81
UML tutorial – Ileana Ober Protocol state machines n Particular state machines used to impose sequencing constraints n Can be attached to interfaces, components, ports, classes n Express n n n Usage protocols Lifecycles for objects Constrain the order of invocation for its operations n Do not preclude any specific behavior description n Protocol conformance must apply between the protocol state machine and the actual implementation n A classifier may own several state machines (ex. due to inheritance) ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 82
UML tutorial – Ileana Ober Syntactic constraints on protocol state machines n No entry, exit, do action on states n No action on its transitions n If a transition is triggered by an operation call, then that operation should apply to the context classifier ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 83
UML tutorial – Ileana Ober Protocol state machine interpretations n Declarative n Specifies legal transitions for each operation n The actual legal transitions for operations are not specified n Defines the contract for the user of the context classifier n Executable n Specifies all events that an object may receive and handle, plus the implied transitions n Legal transitions for operations are the triggered transitions ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 84
UML tutorial – Ileana Ober Protocol state machine example n Notation: {protocol} mark should be placed close to the state machine name ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 85
UML tutorial – Ileana Ober Overview n What is UML? n Structure description n Behavior description n State machine diagrams n Protocol state machine n Activity diagrams n Sequence diagrams n Timing diagrams n OCL n UML and tools ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 86
UML tutorial – Ileana Ober Activity diagrams n Related to state machine diagrams n State diagrams – focus on the execution of a single object n Activity diagram – focus on the behavior of a set of objects n Purpose n Models high-level business processes, including data flow, n Models the logic of complex logic within a system n Concurrency model based on Petri Nets ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 87
UML tutorial – Ileana Ober Activity diagram example ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 88
UML tutorial – Ileana Ober Sequence diagram n Shows a concrete execution scenario, involving: n n objects, actors, generic system Highlights the lifelines of the participating instances Focuses on interaction, exchanged messages and their ordering Give instances of (cooperating) state machine executions Can address various levels of abstraction: n n System level Object sets level Object level Method level ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 89
UML tutorial – Ileana Ober Example john : User : System login(john, climb 5) invalid. ID login(john, climb) : Session welcome ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 90
UML tutorial – Ileana Ober Timing diagram n used to explore the behaviors of one or more objects throughout a given time interval n Mostly interesting for systems with time sensitive behavior w: Walkman t 1+7 switch Off CD Radio t 1+3 CD t 1 switch ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 91
UML tutorial – Ileana Ober Overview n What is UML? n Structure description n Behavior description n State machine diagrams n Protocol state machine n Activity diagrams n Sequence diagrams n Timing diagrams n OCL n UML and tools ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 92
UML tutorial – Ileana Ober OCL – Object Constraint Language n Constraint language integrated in the UML standard n Aims to fill the gap between mathematical rigor and business modeling n Recommended for: Constraints: pre and post conditions, invariants n Boolean expressions: guards, query body specification n Defining initial and derived values of features n n UML meta-model WFRs written in OCL ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 93
UML tutorial – Ileana Ober Example 1 – (all kinds of ) invariants No grandchild may not have more than 2 pet dogs: child Person contex Person inv: self. child. pet -> size()<2 * parent 2 * owner pet* Dog ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 94
UML tutorial – Ileana Ober Example 2 – pre and post conditions contex Automobile: : fill. Tank (in volume: real): real pre: volume>0 pre: tank. Load + volume < max. Load post: tank. Load = tank. Load@pre + volume Vehicle Door 0. . 1 *door Automobile +tank. Load : integer -max. Load: integer +fill. Tank(In volume: real): real ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 95
UML tutorial – Ileana Ober Overview n What is UML? n Structure description n Behavior description n OCL n UML and tools ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 96
UML tutorial – Ileana Ober Although universal, UML can’t contain everything… n Extension mechanisms n Stereotype n n mechanism allowing to specialize particular UML concepts allows to use platform or domain specific terminology e. g. Class stereotyped reactive if it has a state machine n Tagged values – allows to attach information to UML model elements n Profile - a stereotyped package containing model elements that have been customized (e. g. for a specific domain) using stereotypes, tagged definitions and constraints e. g. SPT, UML profile for EDOC, … ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 97
UML tutorial – Ileana Ober Tool support for UML n UML can only live if tool builders support it Just think of a programming language with no compiler… n Tool builders are de facto deciders of live and dead parts of the languages n There is no UML tool that offers all the functionalities one can think of n This part is not a presentation of tools, rather a list a functionalities offered by various tools ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 98
UML tutorial – Ileana Ober Functionalities n n Editing support Documentation generation Syntax check Static semantic check n Code generation n Symbolic execution / simulation n Formal verification n Support for tests on model n Test case generation n Reverse engineering n Model transformation and translations to other formalisms n … ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 99
UML tutorial – Ileana Ober Model interchange n The need n A single tool does not offer all the functionalities n Avoid user kidnapping n The solution n XMI: standardized model interchange format n Offers an XML DTD schema of the metamodel, to be used by tools n The reality n Commercial tools offer limited support (why? ) n The complexity of the UML metamodel often leaves place to interpretations => incompatibilities n Until UML 2. 0 no diagram interchange ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 100
UML tutorial – Ileana Ober Conclusions – UML summary n UML – modeling language to be used throughout the entire software lifecycle n Capture requirements n n Use cases Sequence diagrams n Structure aspects n OO inspired definition n Component support n Behavior aspects n State machines – for reactive behavior n Actions – in general n Deployment aspects n Component/deployment diagrams ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 101
UML tutorial – Ileana Ober UML summary (2/2) n To be as flexible as possible n UML offers extension mechanisms, profiles n Using profile UML can be transformed in a DSL n Tool support n Lots of commercial/non-commercial tools exist n Various functionalities offered n Tool interchange exists, but lots are still to be done ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 102
UML tutorial – Ileana Ober Impact on research activity Researchers attitude evolved: n Hostility: received with skepticism, and (violent) critics n Resign: very used in research papers, projects, books n Pragmatism: taken as it is, used as a bridge with the industrial world n Often the main focus of conferences, workshops, basic research, more as a means than as a goal ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 103
UML tutorial – Ileana Ober The bad news is that … n The various notations within UML are not perfectly coordinated n Often, different tools interpret the UML standard differently n The unique modeling language is in fact a set of dialects ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 104
UML tutorial – Ileana Ober The good news is that … n We have a language allowing to design and model various aspects of systems n This language is standardized and supported by various tools n The tool support and interoperability improves in time, as UML, OCL, and XMI are still relatively young standards ARTIST 2 Summer School on Component & Modelling, Testing & Verification, and Statical Analysis of Embedded Systems Sept 29 - Oct 2, 2005 105
- Slides: 105