Introduction to UML Part 2 1 Building blocks
Introduction to UML Part 2 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 * * 1. . * Office 2
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 - can be 5
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
1. 1. 2 Interface: A Named Set of Operations That Describes Some Behavior (No Implementation) interface name stereotype operation compartment ISortable interface - iconic form interface - expanded form 8
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: The auto-pilot of an airplane can act as a pilot the same is true about some humans. The auto-pilot and the human is quit different types of objects, but they can both play the same role. Many different types of objects can implement the interface, so the interface is not the same as a “class to subclass from”. Interface, Hi. A by J. P. Nytun 2 9
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 10
1. 1. 4 Colloboration Listener Colloboration: describes a colloboration between roles to achieve a particular goal. A collaboration can represent an implementation of a use case or a particular pattern. 11
1. 1. 5 Component calculate. class Component: a physical part of the system which implements a set of interfaces. 12
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. 13
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 14
1. 1. 6 Node video. Server Node: a physical element that represent a computational resource (e. g. processor and memory). 15
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. 16
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» constraint reorder() 17
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 18
1. 2. 1 Interaction: A behavior that comprises a set of messages sent between a set of objects to archive a special purpose, like in a sequence diagram. 19
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. 20
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 21
1. 4 Annotational Elements • You can add comments to a diagram with the help of notes. A comment 22
2 Relations • You have 4 different relationships: – 2. 1 Dependency – 2. 2 Association – 2. 3 Generalitation – 2. 4 Realization 23
2. 1 Dependency: • A relationship between to modeling elements, indicate 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). 24
2. 2 Association: • This relationship indicate that there is a connection from one type of objects to another type. An important type of association is aggregation which indicates that one object contains objects of a given type. Company 1 composition or strong aggregation multiplicity 1. . * Department association name Located. At * * 1. . * Office ordinary association 25
2. 3 Generalization: • A relationship between a more general element and a more specific one. For example: a bird is also an animal. Animal Bird A bird is a specialization of an animal. 26
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) 27
3 Diagrams • A diagram is typically a view of a part of the model, showing modeling elements and some of the relationships between them. • A diagram do not have to be complete, some elements may be missing or presented in a simplified fashion. • UML: ”A well-formed model is one that is semantically self-consistent and in harmony with all related models. ” 28
There are 9 types of diagrams in UML Dynamic views Sequence Diagrams Collaboration Diagrams Activity Diagrams Statechart Diagrams Static views Use Case Diagrams Some part of the model might not be visible on any diagram Class Diagrams Object Diagrams Model Component Diagrams Deployment Diagrams 29
3. 1 Use case diagram actor register a person edit a registration/ delete a registration User association use case ”include” navigate/view the register include relationship ”include” view next person ”include” view previous person system boundary 30
Use Case Diagram - One More Example ”A use case is a specific way of using the system by performing some part of the functionality. Each use case constitutes a complete course of events initiated by an actor, and it specifies the interaction that takes place between an actor and the system. . ” I. Jacobson 31
3. 2 Class Diagram Person name : String email : String home. Page : String 1 responsible for 1 tech. responsible for * Course : String * name description : String Course. Module * 1. . * name : String description : String 1 1 Student 1 * * Student. Course. Profile * finished : boolean When a student register for course a Student. Course. Profile object will be made! 32
A Class Diagram With Navigation 1 Person responsible for name : String 1 tech. responsible for imail : String home. Page : String * Course : String * name description : String Course. Module : String * 1. . * name description : String 1 1 * Student. Course. Profile * finished : boolean 33
A Class Diagram - Mapping to Java 1 Person responsible for name : String 1 tech. responsible for imail : String home. Page : String * Course : String * name description : String 1 Student 1 public class Person { protected String name; protected String imail; protected String home. Page; // // Navigation protected Course[] responsible. For; protected Course[] tech. Responsible. For; public Person() { } } * * Student. Course. Profile finished : boolean public class Student extends Person { // // Navigation public Student. Course. Profile[] student. Course. Profile; public Student() { } } 34
A Class Diagram - Example With Interface <<Interface>> IStorable Register -reg 0. . * relization public void read(){ terminal. print("Name: "); name = terminal. read. Line(); . . . } edit() write() read() Person edit() write() read() relization/implements To different representation of nearly the same dependency 35
A Class Diagram One More Example With Interface 36
3. 3 Object Diagram Capture Instances and Links Class Company no. Of. Emploees : int Object Hi. A: Company no. Of. Emploees=600 Possible object name attribute with value object class 37
Object Diagram with Links Class Diagram Company Object Diagram Language: : Located. At Department Gimlemoen: Office 1 1. . * Located. At Department Office * 1. . * Hi. A: Company Possible object diagram Engineering : Department : Located. At Grooseveien: Office Link - A link is an instance of an association, analogous to an object being an instance of a class. 38
Object diagram and Rational Rose 2000 does not have object diagrams, but you can achieve much the same with a collobartion diagram You can not specify attributes inside object; One solution to this short-coming is to use a comment! 39
3. 4 Sequence diagram user controller. Viewer register <command r> <name, e-mail, . . > ”create” person set. Data(name, . . ) insert(person) 40
3. 5 Colloboration diagram 1. 2: ”create” 1. 3: set. Date(data) 1: register() user controller. Viewer person 1. 1: data : = get. Data() 1. 4: insert(person) register 41
3. 6 Statechart diagram State. Chart for microwave oven "control unit" 42
Statechart for Applet Not Loaded init/init() Running Loaded start stop/ stop() /start() destroy/destroy() start/start() Stopped 43
3. 7 Activity diagram Capture Dynamic Behaviour (Activity-oriented) 44
Activity diagram One More Example activity product of activity 45
Activity diagram - One More Example user controller person register request registration create person (object) supply person-data forward person-data process person-data insert person 46
3. 8 Component diagram Captures the Physical Structure of the Implementation Demo. html applet 1. class applet 1. java applet 2. class applet 2. java logo. gif 47
Component diagram One More Example Person. class Register. class ISortable 48
3. 9 Deployment diagram Extended VLAN ”Server” ”network” LAN ”PC” 49
client: browser: Internet Multi-tier Architecture - MVC - server 1: : Web. Server : html view: browser/jsp/servlet controller: jsp/servlet model: business. Objects : Servlet. Container s 1: Servlet s 2: Servlet b 1: Business. Object j 1: Jsp j 2: Jsp Intranet b 3: Business. Object b 2: Business. Object : DB b 4: Business. Object server 2: 50
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 51
- Slides: 51