Introduction to UML Modeling Elements 1 Building blocks
Introduction to UML Modeling Elements 1
Building blocks of the UML • As part of a model you have: – 1 modelling elements – 2 relationships between the modelling elements – 3 diagrams that group and visualize the modelling elements and the relations between them. • E. g. class diagram: Company 1 1. . * Department 2 Located. At * * 1. . * Office
1 Modelling elements • You have modelling elements for: – 1. 1 Structural things – 1. 2 Behavioural things – 1. 3 Grouping things – 1. 4 Annotational things 3
1. 1 Structural elements • Identified with nouns, e. g. Person; Typically representing static parts of the model. In UML you will find several different types of structural elements, here are some: – 1. 1. 1 Class – 1. 1. 2 Interface – 1. 1. 3 Active class – 1. 1. 4 Colloboration – 1. 1. 5 Component – 1. 1. 6 Node – 1. 1. 7 Use Case 4
1. 1. 1 Class: Describes a Set of Objects class name visibility operation signature Point - x : int - y : int + get. X() : int + set. X(a. X : int) : void + get. Y() : int + set. Y(a. Y : int) : void attributes operations Rational Rose 2000 Rose: The icons , and can be used instead of +, # and – The IBM Rational Software Architect have its own icons. 5
Eclipse Modeling Tools Tips: Preferences can be set by choosing Window/Preferences in the menu: when selected Turn of NB! Does not seems to work completely as specified. It seems that the tree browser works better! 6
My Preferences When attributes and operations are public then the + is not shown. 7
Encapsulation Also Called Data Hiding • Encapsulation: hiding the implementation of the data from users of the object Users are typically objects of other classes. The users don’t see if the data is stored in fields, calculated or if they are retrieved from a database, they only call a method. • Encapsulation is achieve by never letting objects directly access fields Fields should only be accessed through the object’s methods. • Making the fields private (or protected) ensures encapsulation. If you want objects of different types to access the fields, then make public methods (or package accessibility) for this purpose. 8
Operation Versus Method (C++ member function) A method is an implementation of an operation. A method specifies the algorithm or procedure that produces the results of an operation. 9
Association Classes The association between classes may have attributes of its own. This can be modeled by connecting a class to the association. Institute works for Person Job description salary Eclipse Modeling Tools 10
1. 1. 2 Interface: A Named Set of Operations That Describes Some Behaviour (No Implementation) interface name stereotype operation compartment ISortable interface - iconic form interface - expanded form 11
An Interface Can Be Seen As a Protocol • An interface is an agreement on behavior • A class which implements an interface agrees on supporting the specified behavior • An interface can also be seen as a definition of a role, role classes which implements the role are able to play that role. Example: A plane has a certain interface (a stick, . . ), the same interface can also be implemented by a flight simulator. A plane and a flight simulator is two different types of objects, but they have both the same interface (implemented differently). If you don’t have interfaces as modeling elements it would be hard to show that we are talking about the same interface. 12
A Java Example: Interface Action. Listener From the Java documentation: The listener interface for receiving action events. The class that is interested in processing an action event implements this interface, and the object created with that class is registered with a component, using the component's add. Action. Listener method. When the action event occurs, that object's action. Performed method is invoked. Component Button requires someone to support the Action. Listener interface ”interface” Button Action. Listener + add. Action. Listener(actionlistener : Action. Listener) action. Performed(e: Action. Event) One. Listener realize or supplies the Action. Listener interface UML 2. 0 Notation: One. Listener Action. Listener Button 13 One. Listener action. Performed(e: Action. Event)
1. 1. 3 Active Class Snake pos: Point move() bite() Active class: describes objects that owns their own thread; The behavior of these objects can be concurrent with others 14
1. 1. 4 Collaboration Listener Collaboration: describes a collaboration between roles to achieve a particular goal. A collaboration can represent an implementation of a use case or a particular pattern. 15
1. 1. 5 Component calculate. class Component: a physical part of the system which implements a set of interfaces. Example: One. Listener Action. Listener 16 one. Button
Different types of Components (in UML) • Deployment Components: Components these components can be assembled to form a complete executable system. Example: A complete executable application, a dynamic library (DLL), a Java. Bean, a COM+ object. • Work Product Components: Components these components are the basis for making the deployment components. They are not a part of the executable system, but results from the development process. Example: Source code. • Execution Components: Components this components are created by an executing system. Example: a Java. Bean created during runtime. 17
Web Example Working product component Deployment component Menu. html Menu ------Menu. java Could be an execution component, e. g. Produced by a servelet Deployment component Menu. jpg 18
1. 1. 6 Node video. Server Node: a physical element that represent a computational resource (e. g. processor and memory). 19
1. 1. 7 Use Case Register for exam Use case: describes a sequence of actions that yields an observable result for an actor. With use cases you can structure the behavioural things in a model. 20
Extensibility Mechanisms «container» Event. Queue tagged value {version 2. 1} add(e: event) remove(n: int) stereotype {add runs in O(1) time} «query» length(): int «helper function» reorder() 21 constraint
1. 2 Behavioral Elements • Describing the dynamically parts of the model. Behavioral elements are identified with the help of verbs. – 1. 2. 1 Interaction – 1. 2. 2 State 22
1. 2. 1 Interaction User Oven-control -unit Oven-light Set temperature(250 C) heat. On() light. On Interaction: A behaviour that comprises a set of messages sent between a set of objects to archive a special purpose, like in a sequence diagram. 23
1. 2. 2 State Machine State machine: A description of the different states an object can go through in response to events. Events generated by the object can also be shown. An activity diagram is a special case of a state diagram. 24
1. 3 Grouping Elements • You can group elements with the help of packages. • [1]: ”A package may own other elements, including classes, . . . , diagrams, and even other packages. ” • You can use packages to organize your classes (interfaces, . . ) and your diagrams. java applet +Applet 25
1. 4 Annotational Elements • You can add comments to a diagram with the help of notes. A comment 26
Building blocks of the UML • As part of a model you have: – 1 modeling elements – 2 relationships between the modeling elements – 3 diagrams that group and visualize the modeling elements and the relations between them. • E. g. class diagram: Company 1 1. . * Department 27 Located. At * * 1. . * Office
2 Relations • You have 4 different relationships: – 2. 1 Dependency – 2. 2 Association – 2. 3 Generalitation – 2. 4 Realization 28
2. 1 Dependency: • A relationship between two modeling elements indicates that a change in the destination may effect the source. Company Employee add(e : employee) The method add has an employee as argument, so Company-class (source) is dependent of the Employee-class (destination). 29
2. 2. 1 Association: • This relationship indicate that there is a connection from one type of objects to another type. From the UML 2. 1 specification - semantic description of association : “An association declares that there can be links between instances of the associated types. A link is a tuple with one value for each end of the association, where each value is an instance of the type of the end. ” Company 1 composition or strong aggregation multiplicity 1. . * Department Located. At * * ordinary association 30 association name 1. . * Office
2. 2. 2 Composition: • An important type of association is composition which indicates that one object contains objects of a given type. • UML 2. 1 specification: “An association may represent a composite aggregation (i. e. , a whole/part relationship). Only binary associations can be aggregations. Composite aggregation is a strong form of aggregation that requires a part instance be included in at most one composite at a time. If a composite is deleted, all of its parts are normally deleted with it. Note that a part can (where allowed) be removed from a composite before the composite is deleted, and thus not be deleted as part of the composite. Compositions may be linked in a directed acyclic graph with transitive deletion characteristics; that is, deleting an element in one part of the graph will also result in the deletion of all elements of the subgraph below that element. ” composition or strong aggregation Company 31 1 1. . * Department
2. 2. 3 Aggregation: • This is a weaker form of aggregation than composition Like composition no cycles are allowed (over all aggregations) and it should be understood as transitive. • Unlike composition a part instance might be included in more than one aggregation at a time. • Composition defines a directed tree and an aggregation defines a directed graph that does not have cycles. (weak) aggregation Mail 32 1 1. . * Mail. Body
2. 3 Generalization: • A relationship between a more general element and a more specific one. For example: A bird is also an animal. Animal A bird is a specialization of an animal. Bird Eagle 33 Generalization is a transitive relation!
2. 4 Realization: • UML: ”A semantic relationships between classifiers, in which one classifiers specifies a contract that another classifier guarantees to carry out”. ”interface” Movable move(x, y) The class Snake implements the interface Movable. Snake move(x, y) 34
References • [1] Grady Booch, James Rumbaugh and Ivar Jacobson: The Unified Modeling Language User Guide. Addison-Wesley, 1999 • James Rumbaugh, Michael Blaha, William Premerlani, Frederick Eddy and William Lorenzen: Object-Oriented Modeling and Design. Prentice Hall, 1991 • Martin Fowler with Kendall Scott: UML Distilled. Addison-Wesley, 1997 • Terry Quatrani: Visual Modeling with Rational Rose and UML. Addison-Wesley, 1998 • Ari Jaaksi: A Method for Your First Object-Oriented Project. JOOP - The Journal of Object-Oriented Programming, Januar 1998 • Rational software: http: //www. rational. com/uml/documentation. html 35
- Slides: 35