<<

Today’s Lecture

INF 111 / CSE 121: } UML Software Tools and Methods ● Package ● State Transition Diagrams ● Activityyg Diagrams Lecture Notes for Summer Quarter, 2008 ● Communication Diagrams Michele Rousseau

Set 8 – UML – Part 2

Lecture Notes 8 - UML 4

Announcements Package Diagrams

} UML Links: } What is a ? } http://dn.codegear.com/article/31863#us ● A construct that enables you to organize e-case- model elements into groups ● Classes or use cases } A isadiagramwithis a diagram with packages and their dependencies

Lecture Notes 8 - UML 2 Lecture Notes 8 - UML 5

Previously in INF 111/CSE121… Why use package diagrams?

} UML } Increases the level of abstraction for ● Class Diagrams complex diagrams ● Diagrams ● Sequence Diagrams } Depict a high-level overview of your requirements or architecture/design ● A collection of use case or class diagrams } To logically modularize a complex diagram } To organize Java source code Not limited to class and use case diagrams

Because diagrams can get messy

Lecture Notes 8 - UML 3 Lecture Notes 8 - UML 6

1 Package Diagrams: Notation Example

} Represented as tabbed folders

} Can use visibility markers + Public -Private # Protected

Lecture Notes 8 - UML 7 Lecture Notes 8 - UML 10

Relationships Some Basic Tips on Packages Two Types } } Dependencies Use Simple, Descriptive Names ● Changes to one package } Use when you need to Simplify affects another Diagrams ● Import is one type that grants access } Packages Should be Cohesive ● Represented by a dashed } Avoid Cyclic Dependencies Between arrow Packages

} Generalizations ● Represented with an open arrow just like in previously discussed diagrams

Lecture Notes 8 - UML 8 Lecture Notes 8 - UML 11

Use Case Example Types of UML Diagrams Structure . Behavior . (6 types) (4 types) } Class diagrams } } } } State machine diagram } Packaggge diagram } Interaction diagrams } Composite structure ● diagram ● ● Interaction overview } diagram } ● Timing diagram If the appropriate diagram is not part of UML use it anyways

Lecture Notes 8 - UML 9 Lecture Notes 8 - UML 12

2 State Transition Diagrams State Transition EX:

} State Transition Diagrams show the dynamic Digital Watch behavior of a class instance or of a whole system } State: the duration of time during which an object is doing an . } A is a graph in which ● nodes correspond to states and ● directed arcs correspond to transitions ● labeled with names.

When to use : Necessary for those objects whose behavior across many use cases needs to be understood

Lecture Notes 8 - UML 13 Lecture Notes 8 - UML 16

State Transition Diagrams Actions

} A short software process that executes immediately. } An event occurs at a point in time and } A transition may trigger an action. } May be triggered on entry or exit of states (instead of labeling ● transmits information from one object to another each incoming (entry) and outgoing (exit) transition with these actions). } An action occurs in response to an event and } An event may trigger an action without leaving the state, cannot be interrupted ● i.e., without triggering exit and entry actions as a self-transition would do. } An activity is a n oper ati on wi th cer tain } AtitiAn action may trigger even ts, usuall llithbjty in other objects. duration that can be interrupted by another } Actions may take arguments. event } A guard is a logical condition placed before a transition that returns either a true or a false.

Lecture Notes 8 - UML 14 Lecture Notes 8 - 17

State Transition Diagrams: Activities Notation } Can take “longer”, State Name ● i.e., they are processes which last as long as an object is in a certain state. } Are interruptible, } State symbol: Do/Activity ● i.e., an event causing a state transition may abort an Entry/Action activity. Exit/Action } May be constructed from a start and a final action.

Event [Guard] / Action } Transition Symbol:

Lecture Notes 8 - UML 15 Lecture Notes 8 - UML 18

3 Activity Diagrams Activity Diagram: } Describe ATM Ex. ● Procedural logic ● Business process ● Workflow } A flow chart with support for parallel behavior } Branches and Merges model the conditional bhbehavi or } Branch: has a single incoming transition multiple, conditional, outgoing transitions } Merge: where conditional behavior terminates Each branch has a corresponding merge } Represented as a Diamond

Lecture Notes 8 - UML 19 Lecture Notes 8 - UML 22

Activity Diagram (2) Conditional Thread

} Forks and Joins model parallel behavior There are some exceptions to the each } Fork: has a single incoming transition and fork having a corresponding join: multiple outgoing transitions (exhibiting parallel behavior) } Conditional Thread: A condition on } Join: syypnchronizes the parallel behavior ● All parallel behaviors complete at the join the thread originating from the fork } Represented as a thick line to create an exception for the join rule. Each Fork has generally has a corresponding ● If the condition is false then that condition Join is considered to be complete

Lecture Notes 8 - UML 20 Lecture Notes 8 - UML 23

Activity Conditional Thread: Example Diagram: Order Ex.

Lecture Notes 8 - UML 21 Lecture Notes 8 - UML 24

4 Superstates Swimlanes

} What if you need to decompose your activity diagram? } Superstates ● You can show the superstate with the internal behavior inside or ● You can show these in a parent diagram ● You can also use explicit initial and final states Adv: you can decouple the parent from the subsidiary and use it in other contexts

Lecture Notes 8 - UML 25 Lecture Notes 8 - UML 28

Atm Ex. Activity Diagram: Superstate

Lecture Notes 8 - UML 26 Lecture Notes 8 - UML 29

Partitioning an Activity Diagram When do you use Activity Diagrams?

Activity diagrams tell you what is } Modeling parallel behavior happening, but how do you know who } Analyzing a use case does what? ● Trying to understand what actions need to take (in programming – which class is place responsible for each activity) ● Determine behavioral dependencies } Swimlanes: group related activities into } Understanding workflow one column (usually organizationally) ● Documenting the logic of a business process ● You must arrange your diagram into vertical zones } Describing a complicated sequential separated by lines. algorithm ● Can be difficult with complex diagrams } Dealing with multi-threaded applications ◘ In this case use non-linear zones – better than nothing

Lecture Notes 8 - UML 27 Lecture Notes 8 - UML 30

5 Not so good for From Use Cases to Code

} Trying to see how objects collaborate ● Use an interaction diagram for that } Trying to see how an object behaves Select a Perform Perform over its lifeti me use case Use Case Use Case Write Code (or scenario) Analysis Design ● Use a state diagram for that

Lecture Notes 8 - UML 31 Lecture Notes 8 - UML 34

Communication Diagrams Use Case Analysis

} Used to be known as Collaboration Diagrams (UML 1.x) – but modified for 2.0 For each use case in an iteration… } Show interactions between run-time elements 1. Create a use case realization } Similar to sequence diagrams, but ● Focus on objects roles & structure 2. Supplement the Use-Case ● Sequence diagram is better at visualizing processing over descriptions time ◘ if necessary It is an object diagram that shows message passing relationships 3. Find Analysis Classes from Use- Emphasis on the flow of messages among objects, Case Behavior rather than timing and ordering of messages } Sequence Numbers are on arrows rather than 4. Distribute Behavior to Analysis vertical order Classes

Lecture Notes 8 - UML 32 Lecture Notes 8 - UML 35

Communication Diagrams: Ex 1. Use-Case Realization A use-case realization is a collection of UML diagrams which together validate that we have ● the classes Æ Class Diagrams (static relationships) ● responsibilities ● object interactions Æ Interaction Diagrams (dynamic relationships) – could be Sequence or Collaboration necessary to provide the behavior in our use case process.

Lecture Notes 8 - UML 33 Lecture Notes 8 - UML 36

6 2. Supplement the Use-Case 4. Distribute Behavior to Analysis descriptions (if necessary) Class } Beef up your use-case descriptions } Sequence Diagrams ● Can include internal or non-visible behavior } Activity / State Diagrams of the system

● Do you need to do this for all of them? No! ÆInclude just enough detail to understand the classes you will need

Lecture Notes 8 - UML 37 Lecture Notes 8 - UML 40

3. Find Analysis Classes from Next Use-Case Behavior } identify a candidate set of For each resulting analysis class analysis classes Describe the Class's Responsibilities } Analysis Class } Describe the Class's Attributes and Associations ●3 Categories ● Define Class Attributes ◘Entity Æ Business level ● Establish Associations between Analysis • Banking system Æ Customer, account, Classes transaction (e-commerce or old school) ● Describe Event Dependencies between ◘Controller Æ process & sequence aware Analysis Classes • Control & direct the flow of control on an } Establish Traceability execution sequence } Evaluate the Results of Use-Case Analysis ◘Boundary Æ I/O required by the s/w system Lecture Notes 8 - UML 38 Lecture Notes 8 - UML 41

Describe the Class’s Responsibilities Some Notes }Use nouns to determine } Simplify your diagrams using Class Nameclasses Description Responsibilities subsystems Customer Represents the human individual (no Manages the information associated with a company accounts) who may request to specific customer (e.g. email address, ●Packages can be used anywhere reserve a vehicle physical address, phone #, etc.) } Use some underlying concepts Customer Profile Reppppresents a set of properties Manages its attributes and values as a describing the rental preferences for cohesive set of properties associated with a ●Abstraction the associated Customer given Customer. Knows the Customer for which it manages these properties. ●Encapsulation Æ Information hiding Vehicle Represents a physical vehicle that has Knows its status (rented, damaged, dirty, been requested by a customer etc…). Knows the vehicle inventory it is a part ◘Hide design decisions most likely to of, or the reservation it is assigned to. Knows change its schedule for availability ●Polymorphism ◘Use Operations/functions in different Car Rental Example ways Lecture Notes 8 - 39 Lecture Notes 8 - UML 42 UML

7