Introduction to UML Todd Bacastow Penn State University

Introduction to UML Todd Bacastow Penn State University Geography 583 Geospatial System Analysis & Design

What is the UML? • Unified Modeling Language • It is a modeling language, not a process • In 1996, work on the UML was begun by Rational.

UML Diagrams 1. 2. 3. 4. 5. 6. 7. 8. 9. Class Diagrams Use Case Diagrams Collaboration Diagrams Sequence Diagrams Package Diagrams Component Diagrams Deployment Diagrams Activity Diagrams State Diagrams

Class Diagrams • Are the most fundamental UML Diagram. • Describe the classes in the system, and the static relationships between classes. • Class diagrams are used during Analysis, Design and Development.

UML Class Diagram Customer 1 Rental Invoice Rental Item 1. . * 1 0. . 1 1 DVD Movie VHS Movie Video Game Checkout Screen

UML Class Diagram Multiplicity Customer Class Simple 1 Aggregation Rental Invoice Abstract Class Rental Item {abstract} 1. . * 1 0. . 1 Composition DVD Movie Simple (Dependency) Generalization VHS Movie Video Game Association Checkout Screen

Parts of a Class • Classes can have four parts – – Name Attributes Operations Responsibilities • Classes can show visibility and types. • All parts but the Name are optional. My. Class. Name +Some. Public. Attribute : Some. Type -Some. Private. Attribute : Some. Type #Some. Protected. Attribute : Some. Type +Class. Method. One() +Class. Method. Two() Responsibilities -- can optionally be described here.

Object Diagrams • An Object is an instance of a class. • Object names are underlined. • Object diagrams are similar to class diagrams. Many of the same notations are used. • Object diagrams capture instances of classes, and allow the dynamic relationships to be shown. This. One : My. Class. Name +Some. Public. Attribute : Some. Type -Some. Private. Attribute : Some. Type #Some. Protected. Attribute : Some. Type +Class. Method. One() +Class. Method. Two()

Class and Object Diagrams Association Name Class Name Customer +id: integer +name: string Rental Item Rents 0. . 1 0. . n +id: integer +released: date Class Diagram Attributes Object Name Joe: Customer Casablanca: Movie +id: 1667 +name: Joe Smith +id: 22340 +released: 1942 Object Diagram

Use Cases • Describe interactions between users and computer systems (both called actors). • Capture user-visible functions. • Achieve discrete measurable goals. • Are typically used during Analysis and Design.

Use Case Diagram Use Case Actor Identify Movie Customer Open Account Return Movie In-Store Customer Telephone Customer Review Account Status Clerk

Use Case Report • The Use Case Report provides documentation for the Use Case. • A Use Case is not complete without the report. • The elements of the Use Case Report are shown on the right. • Brief description • Precondition • Flow of events – Main flow – Subflows – Alternate flows • Postcondition • Special Requirements • Enclosures – Diagrams – Pictures of the UI

Collaboration Diagrams • Collaboration diagrams describe interactions and links • Focus on exchange of messages between objects • Appears during Analysis phase • Enhanced during Design phase

Collaboration Diagram - Rent Movie : Rented Items 1: enter_customer() 3: enter_movies() Object 5: add(customer, movies) 8: generate. Rental. Total() 2: Is. Valid. Cust(Cust. Id) 7: print invoice() : Check-out Manager : Customer : Clerk 4: Get. Movie. By. Barcode() : Inventory Message

Sequence Diagrams • Can be “morphed” from Collaboration Diagrams. • Describe interactions between objects arranged in time sequence • Focus on objects and classes involved in the scenario and the sequence of messages exchanged • Associated with use cases • Used heavily during Analysis phase and are enhanced and refined during Design phase

Sequence Diagram - Rent Movie : Checkout. Mgr : Cust: Customer : Inventory : Rented. Items Employee 1: find customer() 3: enter movie() 2: search (string) 4: search (string) Object Activation Message 5: rent (movie) 6: add(Cust, item) Lifeline 7: print. Invoice() 8: generate. Rental. Total()

Package Diagram Class Package

Component Diagram Component Interface Dependency Note

Deployment Diagram Node Communication Association

Activity Diagram Start State Identify Caller Action State Obtain Name & Address Current Customer? Decision Open Account? [no] [yes] End State Create Account

Swimlanes and Fork/Join Points Customer Identify Movie Manager Walking Clerk Fork Point Place Order Pay Collect Money Pickup Movie Deliver Movie Fill Order Join Point

State Diagram Guard Event Transition Activity State

UML Diagram Usage

Conclusion • UML is a robust notation that can express information gathered throughout a project’s lifecycle. • Adopting standard use of UML can improve communication between clients and developers. • UML can be used as an effective data modeling tool as well as an object modeling tool.
- Slides: 24