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 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 Located. At * * 2 1. . * Office
1 Modeling elements • You have modeling elements for: – 1. 1 Structural things – 1. 2 Behavioral 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 7 different types of structual elements: – 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 used instead of +, # and 5 can be
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. 6
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. 7
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 8
1. 1. 2 Interface: A Named Set of Operations That Describes Some Behavior (No Implementation) stereotype interface name operation compartment ISortable interface - iconic form interface - expanded form 9
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. 10
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 action. Performed(e: Action. Event) 11
1. 1. 3 Active Class Snake pos: Point move() bite() Active class: describes objects that owns their own thread; The behavior of this objects can be concurrent with others 12
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. 13
1. 1. 5 Component calculate. class Component: a physical part of the system which implements a set of interfaces. Example: One. Listener one. Button Action. Listener 14
Different types of Components (in UML) • Deployment Components: Components this 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 this 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. 15
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 16
1. 1. 6 Node video. Server Node: a physical element that represent a computational resource (e. g. processor and memory). 17
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 behavioral things in a model. 18
Extensibility Mechanisms «container» Event. Queue tagged value {version 2. 1} stereotype add(e: event) remove(n: int) {add runs in O(1) time} «query» length(): int «helper function» reorder() 19 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 20
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. 21
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 is also shown. An activity diagram is a special case of a state diagram. 22
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 orginaze your classes (interfaces, . . ) and your diagrams. java applet +Applet 23
1. 4 Annotational Elements • You can add comments to a diagram with the help of notes. A comment 24
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 25
- Slides: 25