uml diagrams - cs361fall2018.github.io · uml – what is it good for? ... online shopping...

46
UML Diagrams Tuesday, October 30 1

Upload: vuthu

Post on 07-Aug-2019

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

UML DiagramsTuesday, October 30

1

Page 2: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Announcements

Sprint 3 overview

2

Page 3: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Software Diagramming

Useful when you need to communicate, visualize, analyze something, especially something with some structure

3

Page 4: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

4https://en.wikipedia.org/wiki/Gray%27s_Anatomy#/media/File:Gray219.png

Page 5: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

http://www.instructables.com/file/F7847TEFW4JU1UC/

Page 6: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

6

Page 7: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

7

Page 8: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical
Page 9: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Unified Modeling Language (UML)

A set of many visual modeling techniques …

9

Page 10: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical
Page 11: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

UML – what is it good for?Forces you to stop and think about design

Get a high-level picture of the design, better understand, find problems

Communication tool

Vocabulary

Teaching tool

11Marian Petre: ML in

practice. ICSE 2013: 722-731

Page 12: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Some UML diagramsActivity Diagram

Class Diagram

Communication Diagram

Component Diagram

Composite Structure Diagram

Deployment Diagram Interaction Overview Diagram

12http://www.agilemodeling.com/

essays/umlDiagrams.htm

Object Diagram

Package Diagram

Sequence Diagram

State Machine Diagram

Timing Diagram

Use Case Diagram

Page 13: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Classes of UML diagramsBehavior

Depicts the behavioral features of the system or process

Activity, sequence, state machine diagrams

Structure

Depicts the elements of a specification irrespective of time

Class diagram

13

Page 14: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Activity DiagramUsed to model business process, or a single usage scenario, or a business rule

Example:

Online Shopping

Purchasing Ticket from vending machine

Reserving a Flight

14

Page 15: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Activity Diagram

Graphical representations of activities or workflow

Different shapes have different meanings

Flow goes from start to the end

15

Page 16: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Activity Diagram Parts

Black circle represents the start

Rounded rectangle represents actions

Diamonds represent decisions

Black Bars represent concurrent activities

Optional: Partition diagram with lines

16

Page 17: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

initial node

action decision

flow/edge

activity end

fork

join

Page 18: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Exercise

Buy the "UML Distilled" text book from amazon.com

18

Page 19: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Sequence DiagramA Sequence Diagram is an interaction diagram that shows how processes operate with one another and in what order

They typically model usage scenarios, logic of methods, the logic of services

Helpful for understanding asynchronous code

Examples

Submitting comments on a website

Facebook user authentication

19

Page 20: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Sequence Diagram Parts

Each actor is represented as a labeled vertical line

Each message is a horizontal line, with message name written above line

Open arrow heads represent async messages

Dashed lines are responses

20

Page 21: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Sequence Diagrams

21

actor

Lifeline

Focus of Control/

Activation

message

msg name

https://en.wikipedia.org/wiki/Sequence_diagram

checkEmail

Computer Server

sendUnsentEmail

getNewEmail

response

[newEmail] downloadEmail

deleteOldEmail

Page 22: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Exercise

Buy the "UML Distilled" text book from amazon.com

22

Page 23: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

UML State Diagram

A state diagram shows the states of an object. Similar to a other State Diagrams, e.g. State Machine

Examples:

State of phone line

Elevator movement

23

Page 24: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

State Diagram Parts

24

Normal StateName

Activities

Start/Initial State

Stop/Accepting/Final State

Transition

EventName [Guard] / Action

Page 25: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

25

Raw (just test)

Geocoded (geocode != null)

in database (geocode == null)

record

geocoding fails & user retweets

geocoding succeeds

Report Status

Page 26: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Actions vs. ActivitiesActions are associated with transitions, are considered to be processes that occur quickly and are not interruptible

Activities are associated with states, can take longer, and can be interrupted by events

“do” events can iterate

“entry” events happen only on entry to state

26

Page 27: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Use Case Diagrams

Use Case Diagram at its simplest is a representation of a user’s interaction with a system.

Use Cases similar to User Stories, but more formal and more complex

27

Page 28: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Use CaseInclude:

Summary of usage requirements, from users point of view

Basic Course of Events

Alternative Paths

Preconditions / Postconditions

28

Page 29: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

http://agilemodeling.com/artifacts/useCaseDiagram.htm

Student

Obtain Student Loan

Pay FeesFinancial Institution

Enroll in class

Drop ClassRegistrar

Page 30: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Class Diagrams

30

Page 31: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Object Terminology

An object mirrors real world entity

Examples:

Person, student, book, card, game, etc.

31

Page 32: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Object Terminology

Objects Contain (class):

attributes (variables)

functionality (methods)

Objects can have properties or be acted upon

32

Page 33: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Encapsulation

Objects allow data and functionality to be bundled together.

Additionally, access to the data may be restricted to some of the objects components

33

Page 34: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Polymorphism

The ability to send the same message (call a method) to an Object, without knowing how the receiver (Object) will implement the message.

34

Page 35: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Building an Object Oriented Model

Our model should:

represent entities

show connections and interactions

show enough detail to evaluate designs

35

Page 36: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Example class:employee:

has a name,

employee#,

department

an employee is

hired,

fired;

an employee works in one or more projects

36

Page 37: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Attributes

Name

Operations

Page 38: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

UML Class Diagram partsObjects do not exist in isolation

UML supports:

Association

Aggregation and Composition

Generalization

Dependency

38

Page 39: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Most generic kind of relationship

Class Associations

39

:Employeename employee# department

hire() fire() assignProject()

:Officeroom #: # of desks:

add_Employee() remove_Employee()

10..* Works in

Page 40: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Example of an association class

40

:carVIN Year Made Mileage

:personname address DriversLicenseNumber

10..* owns

:titleyearBought price initialMileage

Page 41: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Aggregation and Composition

Aggregation:

This is the “has-a” or “whole/part” relationship

Composition:

implies ownership

41

Page 42: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Aggregation and Composition example

42

:car

:engine

:person

1

1

1

0..1

driver

Composition

Aggregation

Page 43: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

Generalization example

43

Page 44: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

44

Page 45: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

ExerciseBook buying in Amazon

Specific book versions may have differences (online, hard copy, soft copy)

Books are written by authors

Books have reviews

A user (or their account)

45

Page 46: UML Diagrams - cs361fall2018.github.io · UML – what is it good for? ... Online Shopping Purchasing Ticket from vending machine Reserving a Flight 14. Activity Diagram Graphical

http://www.uml-diagrams.org/class-diagrams-overview.html